From 9e255c21392adf612f735381c98ec9e2683d6c21 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 8 Aug 2021 00:54:27 -0400 Subject: [PATCH] lib/helpers: new function to set BASH_IT_HOMEBREW_PREFIX New function `_bash_it_homebrew_check()` sets global variable `$BASH_IT_HOMEBREW_PREFIX` using `brew --prefix` if `brew` exists as a valid command. If `brew` isn't installed, then return failure. Plugins can test for `brew` by calling this function and, if it succeeds, they can rely on `$BASH_IT_HOMEBREW_PREFIX` being defined properly. --- lib/helpers.bash | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/helpers.bash b/lib/helpers.bash index 4d058fd1..82c710a0 100755 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -48,6 +48,19 @@ function _completion_exists () complete -p "$1" &> /dev/null && _log_warning "$msg" ; } +function _bash_it_homebrew_check() +{ + if [[ "${BASH_IT_HOMEBREW_PREFIX:-unset}" == 'unset' ]] + then # variable isn't set + if _binary_exists 'brew' + then # Homebrew is installed + BASH_IT_HOMEBREW_PREFIX="$(brew --prefix)" + else # Homebrew is not installed. + false # return failure if brew not installed. + fi + fi +} + function _make_reload_alias() { echo "source \${BASH_IT}/scripts/reloader.bash ${1} ${2}" }