55
66if shopt -qo nounset
77then # Bash-completion is too large and complex to expect to handle unbound variables throughout the whole codebase.
8- BASH_IT_RESTORE_NOUNSET =true
8+ __bash_it_restore_nounset =true
99 shopt -uo nounset
1010else
11- BASH_IT_RESTORE_NOUNSET =false
11+ __bash_it_restore_nounset =false
1212fi
1313
1414if [[ -r " ${BASH_COMPLETION:- } " ]] ; then
15+ # shellcheck disable=SC1091
1516 source " ${BASH_COMPLETION} "
17+
1618elif [[ -r /etc/bash_completion ]] ; then
1719 # shellcheck disable=SC1091
1820 source /etc/bash_completion
@@ -23,17 +25,37 @@ elif [[ -r /etc/profile.d/bash_completion.sh ]] ; then
2325 source /etc/profile.d/bash_completion.sh
2426
2527elif [[ $OSTYPE == ' darwin' * ]] && _command_exists brew ; then
26- BREW_PREFIX=${BREW_PREFIX:- $(brew --prefix)}
28+ : ${BREW_PREFIX:- $(brew --prefix)}
29+ : ${BASH_COMPLETION_COMPAT_DIR:= $BREW_PREFIX / etc/ bash_completion.d}
2730
28- # homebrew/versions/bash-completion2 (required for projects.completion.bash) is installed to this path
29- if [[ -r " $BREW_PREFIX " /etc/bash_completion ]] ; then
30- # shellcheck disable=SC1090
31- source " $BREW_PREFIX " /etc/bash_completion
32- fi
31+ case " ${BASH_VERSION} " in
32+ 1* |2* |3.0* |3.1* )
33+ _log_warning " Cannot load completion due to version of shell."
34+ ;;
35+ 3.2* |4.0* |4.1* )
36+ # Import version 1.x of bash-completion, if installed.
37+ BASH_COMPLETION=" $BREW_PREFIX /opt/bash-completion@1/etc/bash_completion"
38+ if [[ -r " $BASH_COMPLETION " ]] ; then
39+ # shellcheck disable=SC1090
40+ source " $BASH_COMPLETION "
41+ else
42+ unset BASH_COMPLETION
43+ fi
44+ ;;
45+ 4.2* |5* |* )
46+ # homebrew/versions/bash-completion2 (required for projects.completion.bash) is installed to this path
47+ if [[ -r " $BREW_PREFIX /opt/bash-completion@2/etc/profile.d/bash_completion.sh" ]] ; then
48+ # shellcheck disable=SC1090
49+ source " $BREW_PREFIX /opt/bash-completion@2/etc/profile.d/bash_completion.sh"
50+ else
51+ unset BASH_COMPLETION
52+ fi
53+ ;;
54+ esac
3355fi
3456
35- if $BASH_IT_RESTORE_NOUNSET
57+ if $__bash_it_restore_nounset
3658then
3759 shopt -so nounset
3860fi
39- unset BASH_IT_RESTORE_NOUNSET
61+ unset __bash_it_restore_nounset
0 commit comments