Skip to content

Instantly share code, notes, and snippets.

@rawiriblundell
Created October 21, 2020 21:29
Show Gist options
  • Save rawiriblundell/5d3848fcf57ca759cd655986cf48b381 to your computer and use it in GitHub Desktop.
Save rawiriblundell/5d3848fcf57ca759cd655986cf48b381 to your computer and use it in GitHub Desktop.
Function to check if a package managed by homebrew is installed
brew::is_installed() {
local failcount
failcount=0
if ! command -v brew >/dev/null 2>&1; then
printf -- '%s\n' "This script requires brew on a mac. This wasn't found..." >&2
exit 1
fi
for brew_pkg in ${*:?Package unspecified}; do
if brew list | grep -w "${brew_pkg}" >/dev/null 2>&1; then
printf -- '%s\n' "${brew_pkg} appears to be installed"
else
printf -- '%s\n' "${brew_pkg} is not installed"
(( failcount++ ))
fi
done
(( failcount > 0 )) && return 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment