Skip to content

Commit f2bff34

Browse files
authored
Merge pull request #2013 from gaelicWizard/completion/system
completion/system: load earlier than others
2 parents 1fd601d + 04c7424 commit f2bff34

File tree

4 files changed

+45
-43
lines changed

4 files changed

+45
-43
lines changed

clean_files.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ completion/available/pipenv.completion.bash
7272
completion/available/pipx.completion.bash
7373
completion/available/rustup.completion.bash
7474
completion/available/sdkman.completion.bash
75+
completion/available/system.completion.bash
7576
completion/available/vault.completion.bash
7677
completion/available/vuejs.completion.bash
7778
completion/available/wpscan.completion.bash
Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,60 @@
1-
#!/usr/bin/env bash
1+
# shellcheck shell=bash
22
#
33
# Loads the system's Bash completion modules.
44
# If Homebrew is installed (OS X), it's Bash completion modules are loaded.
55

6-
if shopt -qo nounset
7-
then # Bash-completion is too large and complex to expect to handle unbound variables throughout the whole codebase.
6+
# Load before other completions
7+
# BASH_IT_LOAD_PRIORITY: 325
8+
9+
# Bash-completion is too large and complex to expect to handle unbound variables throughout the whole codebase.
10+
if shopt -qo nounset; then
811
__bash_it_restore_nounset=true
912
shopt -uo nounset
1013
else
1114
__bash_it_restore_nounset=false
1215
fi
1316

14-
if [[ -r "${BASH_COMPLETION:-}" ]] ; then
15-
# shellcheck disable=SC1091
17+
if [[ -r "${BASH_COMPLETION:-}" ]]; then
18+
# shellcheck disable=SC1090
1619
source "${BASH_COMPLETION}"
1720

18-
elif [[ -r /etc/bash_completion ]] ; then
19-
# shellcheck disable=SC1091
20-
source /etc/bash_completion
21+
elif [[ -r /etc/bash_completion ]]; then
22+
# shellcheck disable=SC1091
23+
source /etc/bash_completion
2124

2225
# Some distribution makes use of a profile.d script to import completion.
23-
elif [[ -r /etc/profile.d/bash_completion.sh ]] ; then
24-
# shellcheck disable=SC1091
25-
source /etc/profile.d/bash_completion.sh
26-
27-
elif _bash_it_homebrew_check
28-
then
29-
: ${BASH_COMPLETION_COMPAT_DIR:=$BASH_IT_HOMEBREW_PREFIX/etc/bash_completion.d}
30-
31-
case "${BASH_VERSION}" in
32-
1*|2*|3.0*|3.1*)
33-
_log_warning "Cannot load completion due to version of shell. Are you using Bash 3.2+?"
34-
;;
35-
3.2*|4.0*|4.1*)
36-
# Import version 1.x of bash-completion, if installed.
37-
BASH_COMPLETION="$BASH_IT_HOMEBREW_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 "$BASH_IT_HOMEBREW_PREFIX"/etc/profile.d/bash_completion.sh ]] ; then
48-
# shellcheck disable=SC1090
49-
source "$BASH_IT_HOMEBREW_PREFIX"/etc/profile.d/bash_completion.sh
50-
fi
51-
;;
52-
esac
26+
elif [[ -r /etc/profile.d/bash_completion.sh ]]; then
27+
# shellcheck disable=SC1091
28+
source /etc/profile.d/bash_completion.sh
29+
30+
elif _bash_it_homebrew_check; then
31+
: "${BASH_COMPLETION_COMPAT_DIR:=$BASH_IT_HOMEBREW_PREFIX/etc/bash_completion.d}"
32+
33+
case "${BASH_VERSION}" in
34+
1* | 2* | 3.0* | 3.1*)
35+
_log_warning "Cannot load completion due to version of shell. Are you using Bash 3.2+?"
36+
;;
37+
3.2* | 4.0* | 4.1*)
38+
# Import version 1.x of bash-completion, if installed.
39+
BASH_COMPLETION="$BASH_IT_HOMEBREW_PREFIX/opt/bash-completion@1/etc/bash_completion"
40+
if [[ -r "$BASH_COMPLETION" ]]; then
41+
# shellcheck disable=SC1090
42+
source "$BASH_COMPLETION"
43+
else
44+
unset BASH_COMPLETION
45+
fi
46+
;;
47+
4.2* | 5* | *)
48+
# homebrew/versions/bash-completion2 (required for projects.completion.bash) is installed to this path
49+
if [[ -r "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh" ]]; then
50+
# shellcheck disable=SC1091
51+
source "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh"
52+
fi
53+
;;
54+
esac
5355
fi
5456

55-
if $__bash_it_restore_nounset
56-
then
57+
if [[ ${__bash_it_restore_nounset:-false} == "true" ]]; then
5758
shopt -so nounset
5859
fi
5960
unset __bash_it_restore_nounset

test/install/install.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function local_setup {
3131
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash"
3232
assert_link_exist "$BASH_IT/enabled/365---alias-completion.plugin.bash"
3333
assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash"
34-
assert_link_exist "$BASH_IT/enabled/350---system.completion.bash"
34+
assert_link_exist "$BASH_IT/enabled/325---system.completion.bash"
3535
}
3636

3737
@test "install: verify that a backup file is created" {

test/lib/helpers.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ function local_setup {
296296
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash"
297297
assert_link_exist "$BASH_IT/enabled/365---alias-completion.plugin.bash"
298298
assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash"
299-
assert_link_exist "$BASH_IT/enabled/350---system.completion.bash"
299+
assert_link_exist "$BASH_IT/enabled/325---system.completion.bash"
300300
}
301301

302302
@test "helper: profile save command sanity" {
@@ -356,7 +356,7 @@ function local_setup {
356356
assert_link_not_exist "$BASH_IT/enabled/250---base.plugin.bash"
357357
assert_link_not_exist "$BASH_IT/enabled/365---alias-completion.plugin.bash"
358358
assert_link_not_exist "$BASH_IT/enabled/350---bash-it.completion.bash"
359-
assert_link_not_exist "$BASH_IT/enabled/350---system.completion.bash"
359+
assert_link_not_exist "$BASH_IT/enabled/325---system.completion.bash"
360360
}
361361

362362
@test "helper: profile save and load" {

0 commit comments

Comments
 (0)