MacOS – Check brew and brew-cask for valid package names

command linehomebrewmacos

I have a iMac and Macbook for work and another set for home. I end up getting a new one every couple of years so I end up re-setting up everything atleast couple of times a year. So I wrote a script to automate as much as possible: https://github.com/pathikrit/mac-setup-script/blob/master/setup.sh

The only problem with above script is that there is no way for me to pre-check if a brew or a brew-cask package is still valid e.g. I want to something like brew check foo to make sure that brew still knows about foo. How do I do that?

Best Answer

To get a list of invalid brew formulas:

#!/usr/bin/env bash
for formula in ${brews[@]}; do
    brew info ${formula} >/dev/null 2>&1 || echo ${formula}
done

To get a list of invalid casks:

#!/usr/bin/env bash
for cask in ${casks[@]}; do
    brew cask info ${cask} >/dev/null 2>&1 || echo ${cask}
done

(brews and casks are the arrays defined in your setup script.)