Last active
June 30, 2024 02:25
-
-
Save zakkhoyt/426cc6a5c2855d1b2feb4169df83bc9b to your computer and use it in GitHub Desktop.
Offer brew install
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
#!/bin/bash | |
# Available as a gist: https://gist.github.com/zakkhoyt/426cc6a5c2855d1b2feb4169df83bc9b | |
BINARY_TOOL="jq" | |
ANSI_BINARY_TOOL="\033[1m${BINARY_TOOL}\033[0m" | |
offer_brew_install() { | |
input="" | |
repeat=false | |
INSTALL_COMMAND="brew install ${BINARY_TOOL}" | |
ANSI_INSTALL_COMMAND="\033[93m${INSTALL_COMMAND}\033[0m" | |
while [ "$repeat" ] | |
do | |
echo -e "" | |
echo -e "Would you like to install ${BINARY_TOOL}?" | |
echo -e "" | |
echo -e " [y] Yes" | |
echo -e " [n] No" | |
echo -e " [p] Print the install command" | |
echo -e " [a] Ask again" | |
echo -e "" | |
read -r input | |
case $input in | |
"y") | |
echo -e "${ANSI_INSTALL_COMMAND}" 1>&2 | |
eval "${INSTALL_COMMAND}" | |
# TODO: zakkhoyt - check for success and update stderr | |
break;; | |
"n") | |
break;; | |
"p") | |
echo -e "${ANSI_INSTALL_COMMAND}" 1>&2 | |
break;; | |
*) | |
repeat=true;; | |
esac | |
done | |
} | |
if which "${BINARY_TOOL}" > /dev/null; then | |
echo -e "${ANSI_BINARY_TOOL} is already installed" 1>&2 | |
else | |
offer_brew_install | |
fi | |
# ------- Or, if you want to source as a function | |
#!/bin/bash | |
# Available as a gist: https://gist.github.com/zakkhoyt/426cc6a5c2855d1b2feb4169df83bc9b | |
verify_brew_install() { | |
if [[ -z "$1" ]]; then | |
# TODO: zakkhoyt - communicate | |
exit 1 | |
fi | |
BINARY_TOOL="$1" | |
ANSI_BINARY_TOOL="\033[1m${BINARY_TOOL}\033[0m" | |
if which "${BINARY_TOOL}" > /dev/null; then | |
echo -e "${ANSI_BINARY_TOOL} is already installed" 1>&2 | |
else | |
input="" | |
repeat=false | |
INSTALL_COMMAND="brew install ${BINARY_TOOL}" | |
ANSI_INSTALL_COMMAND="\033[93m${INSTALL_COMMAND}\033[0m" | |
while [ "$repeat" ] | |
do | |
echo -e "" | |
echo -e "Would you like to install ${BINARY_TOOL}?" | |
echo -e "" | |
echo -e " [y] Yes" | |
echo -e " [n] No" | |
echo -e " [p] Print the install command" | |
echo -e " [a] Ask again" | |
echo -e "" | |
read -r input | |
case $input in | |
"y") | |
echo -e "${ANSI_INSTALL_COMMAND}" 1>&2 | |
eval "${INSTALL_COMMAND}" | |
# TODO: zakkhoyt - check for success and update stderr | |
break;; | |
"n") | |
break;; | |
"p") | |
echo -e "${ANSI_INSTALL_COMMAND}" 1>&2 | |
break;; | |
*) | |
repeat=true;; | |
esac | |
done | |
fi | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment