Skip to content

Commit

Permalink
Merge pull request #2013 from gaelicWizard/completion/system
Browse files Browse the repository at this point in the history
completion/system: load earlier than others
  • Loading branch information
NoahGorny authored Jan 8, 2022
2 parents 1fd601d + 04c7424 commit f2bff34
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 43 deletions.
1 change: 1 addition & 0 deletions clean_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ completion/available/pipenv.completion.bash
completion/available/pipx.completion.bash
completion/available/rustup.completion.bash
completion/available/sdkman.completion.bash
completion/available/system.completion.bash
completion/available/vault.completion.bash
completion/available/vuejs.completion.bash
completion/available/wpscan.completion.bash
Expand Down
81 changes: 41 additions & 40 deletions completion/available/system.completion.bash
Original file line number Diff line number Diff line change
@@ -1,59 +1,60 @@
#!/usr/bin/env bash
# shellcheck shell=bash
#
# Loads the system's Bash completion modules.
# If Homebrew is installed (OS X), it's Bash completion modules are loaded.

if shopt -qo nounset
then # Bash-completion is too large and complex to expect to handle unbound variables throughout the whole codebase.
# Load before other completions
# BASH_IT_LOAD_PRIORITY: 325

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

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

elif [[ -r /etc/bash_completion ]] ; then
# shellcheck disable=SC1091
source /etc/bash_completion
elif [[ -r /etc/bash_completion ]]; then
# shellcheck disable=SC1091
source /etc/bash_completion

# Some distribution makes use of a profile.d script to import completion.
elif [[ -r /etc/profile.d/bash_completion.sh ]] ; then
# shellcheck disable=SC1091
source /etc/profile.d/bash_completion.sh

elif _bash_it_homebrew_check
then
: ${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
elif [[ -r /etc/profile.d/bash_completion.sh ]]; then
# shellcheck disable=SC1091
source /etc/profile.d/bash_completion.sh

elif _bash_it_homebrew_check; then
: "${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=SC1091
source "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh"
fi
;;
esac
fi

if $__bash_it_restore_nounset
then
if [[ ${__bash_it_restore_nounset:-false} == "true" ]]; then
shopt -so nounset
fi
unset __bash_it_restore_nounset
2 changes: 1 addition & 1 deletion test/install/install.bats
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function local_setup {
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash"
assert_link_exist "$BASH_IT/enabled/365---alias-completion.plugin.bash"
assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash"
assert_link_exist "$BASH_IT/enabled/350---system.completion.bash"
assert_link_exist "$BASH_IT/enabled/325---system.completion.bash"
}

@test "install: verify that a backup file is created" {
Expand Down
4 changes: 2 additions & 2 deletions test/lib/helpers.bats
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ function local_setup {
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash"
assert_link_exist "$BASH_IT/enabled/365---alias-completion.plugin.bash"
assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash"
assert_link_exist "$BASH_IT/enabled/350---system.completion.bash"
assert_link_exist "$BASH_IT/enabled/325---system.completion.bash"
}

@test "helper: profile save command sanity" {
Expand Down Expand Up @@ -356,7 +356,7 @@ function local_setup {
assert_link_not_exist "$BASH_IT/enabled/250---base.plugin.bash"
assert_link_not_exist "$BASH_IT/enabled/365---alias-completion.plugin.bash"
assert_link_not_exist "$BASH_IT/enabled/350---bash-it.completion.bash"
assert_link_not_exist "$BASH_IT/enabled/350---system.completion.bash"
assert_link_not_exist "$BASH_IT/enabled/325---system.completion.bash"
}

@test "helper: profile save and load" {
Expand Down

0 comments on commit f2bff34

Please sign in to comment.