I am currently planning to reinstall my OS from scratch. Over the years, I installed a LOT OF packages via brew. Obviously, I'd like to reinstall those after setting up the system again, and I want to automate this as much as possible.
Hence my question: How do I list all packages installed via brew, including casks, and how do I create an "install script" from those that will add all added casks for me and then install all packages again?"
Apple Silicon: port all Homebrew packages under /usr/local/opt/ to /opt/homebrew asks a similar question, but doesn't address the creation of a automated install script, rather the port between two architectures.