Skip to content

Commit

Permalink
Merge pull request Bash-it#1915 from gaelicWizard/bash_completion
Browse files Browse the repository at this point in the history
Support multiple versions of _Bash Completion_
  • Loading branch information
Noah Gorny authored Sep 7, 2021
2 parents 5782325 + feacd56 commit 9ea6002
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions completion/available/system.completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@

if shopt -qo nounset
then # Bash-completion is too large and complex to expect to handle unbound variables throughout the whole codebase.
BASH_IT_RESTORE_NOUNSET=true
__bash_it_restore_nounset=true
shopt -uo nounset
else
BASH_IT_RESTORE_NOUNSET=false
__bash_it_restore_nounset=false
fi

if [[ -r "${BASH_COMPLETION:-}" ]] ; then
# shellcheck disable=SC1091
source "${BASH_COMPLETION}"

elif [[ -r /etc/bash_completion ]] ; then
# shellcheck disable=SC1091
source /etc/bash_completion
Expand All @@ -24,15 +26,34 @@ elif [[ -r /etc/profile.d/bash_completion.sh ]] ; then

elif _bash_it_homebrew_check
then
# homebrew/versions/bash-completion2 (required for projects.completion.bash) is installed to this path
if [[ -r "$BASH_IT_HOMEBREW_PREFIX"/etc/profile.d/bash_completion.sh ]] ; then
# shellcheck disable=SC1090
source "$BASH_IT_HOMEBREW_PREFIX"/etc/profile.d/bash_completion.sh
fi
: ${BASH_COMPLETION_COMPAT_DIR:=$BASH_IT_HOMEBREW_PREFIX/etc/bash_completion.d}

case "${BASH_VERSION}" in
1*|2*|3.0*|3.1*)
_log_warning "Cannot load completion due to version of shell. Are you using Bash 3.2+?"
;;
3.2*|4.0*|4.1*)
# Import version 1.x of bash-completion, if installed.
BASH_COMPLETION="$BASH_IT_HOMEBREW_PREFIX/opt/bash-completion@1/etc/bash_completion"
if [[ -r "$BASH_COMPLETION" ]] ; then
# shellcheck disable=SC1090
source "$BASH_COMPLETION"
else
unset BASH_COMPLETION
fi
;;
4.2*|5*|*)
# homebrew/versions/bash-completion2 (required for projects.completion.bash) is installed to this path
if [[ -r "$BASH_IT_HOMEBREW_PREFIX"/etc/profile.d/bash_completion.sh ]] ; then
# shellcheck disable=SC1090
source "$BASH_IT_HOMEBREW_PREFIX"/etc/profile.d/bash_completion.sh
fi
;;
esac
fi

if $BASH_IT_RESTORE_NOUNSET
if $__bash_it_restore_nounset
then
shopt -so nounset
fi
unset BASH_IT_RESTORE_NOUNSET
unset __bash_it_restore_nounset

0 comments on commit 9ea6002

Please sign in to comment.