Last active
March 4, 2021 22:36
-
-
Save ink-splatters/c46ca3523b5a6da56bb25cd982c58b95 to your computer and use it in GitHub Desktop.
HomeBrew convinience install_or_upgrade CLI func
This file contains 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
c46ca3523b5a6da56bb25cd982c58b95_cmd() { | |
echo "[INFO] $@" ; sh -c "$@" | |
} | |
brew_install_or_upgrade() { | |
# shellcheck disable=SC2206 | |
local tools=($@) | |
# shellcheck disable=SC2155 | |
local -a installed | |
echo [INFO] checking installed... | |
installed=$(brew list --formula) | |
local -a install=() | |
local -a upgrade=() | |
for tool in "${tools[@]}" ; do | |
# shellcheck disable=SC2046 | |
# shellcheck disable=SC2155 | |
if [ "$(echo "$installed" | grep -o $tool)" == "$tool" ]; then | |
upgrade+=("$tool") | |
else | |
install+=("$tool") | |
fi | |
done | |
if [[ ${#install[@]} -gt 0 ]]; then | |
echo Installing ${install[*]}... | |
c46ca3523b5a6da56bb25cd982c58b95_cmd brew install --formula ${install[*]} | |
fi | |
if [[ ${#upgrade[@]} -gt 0 ]]; then | |
echo Upgrading ${upgrade[*]}... | |
c46ca3523b5a6da56bb25cd982c58b95_cmd brew upgrade --formula ${upgrade[*]} | |
fi | |
} | |
echo '[INFO] using brew_install_or_upgrade' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment