Skip to content

Commit 573889e

Browse files
committed
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.
1 parent 9ea290a commit 573889e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/helpers.bash

100644100755
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ function _completion_exists ()
4848
complete -p "$1" &> /dev/null && _log_warning "$msg" ;
4949
}
5050

51+
function _bash_it_homebrew_check()
52+
{
53+
if [[ "${BASH_IT_HOMEBREW_PREFIX:-unset}" == 'unset' ]]
54+
then # variable isn't set
55+
if _binary_exists 'brew'
56+
then # Homebrew is installed
57+
BASH_IT_HOMEBREW_PREFIX="$(brew --prefix)"
58+
else # Homebrew is not installed.
59+
false # return failure if brew not installed.
60+
fi
61+
fi
62+
}
63+
5164
function _make_reload_alias() {
5265
echo "source \${BASH_IT}/scripts/reloader.bash ${1} ${2}"
5366
}

0 commit comments

Comments
 (0)