Created
October 21, 2020 21:29
-
-
Save rawiriblundell/5d3848fcf57ca759cd655986cf48b381 to your computer and use it in GitHub Desktop.
Function to check if a package managed by homebrew is installed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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