Skip to content

Commit 23d54a0

Browse files
committed
Use _bash_it_homebrew_check() in plugins, completions
Use new function `_bash_it_homebrew_check()` in existing plugins and completions which look for Homebrew. Alsö, use `$OSTYPE` instead of calling external `uname` binary.
1 parent 2f6d1c8 commit 23d54a0

4 files changed

Lines changed: 15 additions & 18 deletions

File tree

completion/available/brew.completion.bash

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,20 @@ if [[ "$OSTYPE" != 'darwin'* ]]; then
1111
fi
1212

1313
# Make sure brew is installed
14-
_command_exists brew || return 0
14+
_bash_it_homebrew_check || return 0
1515

16-
BREW_PREFIX=${BREW_PREFIX:-$(brew --prefix)}
17-
18-
if [[ -r "$BREW_PREFIX"/etc/bash_completion.d/brew ]]; then
16+
if [[ -r "$BASH_IT_HOMEBREW_PREFIX/etc/bash_completion.d/brew" ]]; then
1917
# shellcheck disable=1090
20-
source "$BREW_PREFIX"/etc/bash_completion.d/brew
18+
source "$BASH_IT_HOMEBREW_PREFIX/etc/bash_completion.d/brew"
2119

22-
elif [[ -r "$BREW_PREFIX"/Library/Contributions/brew_bash_completion.sh ]]; then
20+
elif [[ -r "$BASH_IT_HOMEBREW_PREFIX/Library/Contributions/brew_bash_completion.sh" ]]; then
2321
# shellcheck disable=1090
24-
source "$BREW_PREFIX"/Library/Contributions/brew_bash_completion.sh
22+
source "$BASH_IT_HOMEBREW_PREFIX/Library/Contributions/brew_bash_completion.sh"
2523

26-
elif [[ -f "$BREW_PREFIX"/completions/bash/brew ]]; then
24+
elif [[ -f "$BASH_IT_HOMEBREW_PREFIX/completions/bash/brew" ]]; then
2725
# For the git-clone based installation, see here for more info:
2826
# https://github.com/Bash-it/bash-it/issues/1458
2927
# https://docs.brew.sh/Shell-Completion
3028
# shellcheck disable=1090
31-
source "$BREW_PREFIX"/completions/bash/brew
29+
source "$BASH_IT_HOMEBREW_PREFIX/completions/bash/brew"
3230
fi

completion/available/system.completion.bash

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ elif [[ -r /etc/profile.d/bash_completion.sh ]] ; then
1414
# shellcheck disable=SC1091
1515
source /etc/profile.d/bash_completion.sh
1616

17-
elif [[ $OSTYPE == 'darwin'* ]] && _command_exists brew ; then
18-
BREW_PREFIX=${BREW_PREFIX:-$(brew --prefix)}
19-
17+
elif _bash_it_homebrew_check
18+
then
2019
# homebrew/versions/bash-completion2 (required for projects.completion.bash) is installed to this path
21-
if [[ -r "$BREW_PREFIX"/etc/bash_completion ]] ; then
20+
if [[ -r "$BASH_IT_HOMEBREW_PREFIX"/etc/profile.d/bash_completion.sh ]] ; then
2221
# shellcheck disable=SC1090
23-
source "$BREW_PREFIX"/etc/bash_completion
22+
source "$BASH_IT_HOMEBREW_PREFIX"/etc/profile.d/bash_completion.sh
2423
fi
2524
fi

plugins/available/autojump.plugin.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ about-plugin 'Autojump configuration, see https://github.com/wting/autojump for
33

44
# Only supports the Homebrew variant, Debian and Arch at the moment.
55
# Feel free to provide a PR to support other install locations
6-
if command -v brew &>/dev/null && [[ -s $(brew --prefix)/etc/profile.d/autojump.sh ]]; then
7-
. $(brew --prefix)/etc/profile.d/autojump.sh
6+
if _bash_it_homebrew_check && [[ -s "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/autojump.sh" ]]; then
7+
. "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/autojump.sh"
88
elif command -v dpkg &>/dev/null && dpkg -s autojump &>/dev/null ; then
99
. "$(dpkg-query -S autojump.sh | cut -d' ' -f2)"
1010
elif command -v pacman &>/dev/null && pacman -Q autojump &>/dev/null ; then

plugins/available/nvm.plugin.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ about-plugin 'node version manager configuration'
99

1010
export NVM_DIR=${NVM_DIR:-$HOME/.nvm}
1111
# This loads nvm
12-
if command -v brew &>/dev/null && [ -s $(brew --prefix nvm)/nvm.sh ]
12+
if _bash_it_homebrew_check && [ -s "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh" ]
1313
then
14-
. $(brew --prefix nvm)/nvm.sh
14+
. "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh"
1515
else
1616
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
1717
fi

0 commit comments

Comments
 (0)