After all these years I have decided to tidy up my computing devices and make replacing/restoring them easier. One way to do this is by creating a Brew bundle that makes reinstalling all of my apps easier. It is pretty simple really if you use Homebrew as your package manager.
brew bundle dump
This command output a list of all your files installed with brew to a Brewfile. You can use it to dump a list of your Mac apps installed from the Mac App Store and VSCode extensions as well. This will make getting up and running on a new machine or maybe after a failed HDD really quick.
I thought this is great but I have a local git repo for my dotfiles it would be great if I can store the Brewfile in there without much extra effort by machine name. Turn out this is pretty easy by setting an environment variable with the location and name of the Brewfile.
export HOMEBREW_BUNDLE_FILE="~/dotfiles/Brewfile.$(hostname -s)"
I add this to my .zshrc and push it to all my machines. When I run brew bundle in the future it will just save to that location and tack the hostname onto it as an extension making it easy to find and in my local git repo by machine name.
There is one tiny catch. By default bundle will not overwrite an existing Brewfile. The simple solution is just to add the –force flag to the end of the bundle command.
brew bundle dump --force
Now when I add a new app I can just run the bundle command and then git commit to save it to my git repo on my home server. This makes reinstallation’s simple and efficient.