Keep a log of Homebrew installations
I love Homebrew and I use it on several different computers. I also have this thing where I like to reinstall OS X often, so I find myself needing to reinstall things like brew.
How do I keep track of what brew formulas I install?
Well, I adapted an idea from Macworld about tracking the defaults command and made my own little zsh function which is also called brew:
brew () {
if [ "$1" = "install" ]
then
LOG="$HOME/Dropbox/etc/logs/brews.txt"
echo "\n\nbrew $@:" >>| "$LOG"
command brew $@ | tee -a "$LOG"
BREW_EXIT="$?"
echo "brew $@ [exit = ${BREW_EXIT}]" >>| "$LOG"
else
command brew $@
fi
}
What that does:
If you type brew install (whatever) this script will intercept it and save it to a file (“$HOME/Dropbox/etc/logs/brews.txt”) so I can find it again later.
Then it will run the actual brew command and save the output of the install to that same file.
Finally, it will check the exit code of the actual brew install command and log that too (zero = good, anything else = bad)
If you run any other brew command such as brew info (whatever) that will not be logged.
Wednesday, February 22, 2012 at 5:26AM