In similar vein to Hans Fredric, here is a snippet I actually use myself. The funny looking <(cmd)
is Bash command substitution.
alias strip-empty="egrep -v '^\s*$'"
NOT_INSTALLED=$(comm -23 <(sort < apps.local) <( brew list --versions | awk '{print $1}' ) | strip-empty)
while read FORMULA; do
brew install "$FORMULA"
done <<< "$NOT_INSTALLED"
Here, apps.local
is just a list of apps to install, one per line. The improvement over just looping over each app and trying something like brew_install
basically comes down to speed. Invoking brew list
is slow (like up to a second), so I just do the test once by listing out all installed apps. The difference is very noticeable if you have > 5 apps.
If you need something with the same speed, but that works equally well with apps installed using a cask, you need something more elaborate (like this).
which <programname>
is faster thanbrew list <programname>
.