|
1 |
| -#!/usr/bin/env bash |
| 1 | +# shellcheck shell=bash |
2 | 2 | #
|
3 | 3 | # Loads the system's Bash completion modules.
|
4 | 4 | # If Homebrew is installed (OS X), it's Bash completion modules are loaded.
|
5 | 5 |
|
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 |
8 | 11 | __bash_it_restore_nounset=true
|
9 | 12 | shopt -uo nounset
|
10 | 13 | else
|
11 | 14 | __bash_it_restore_nounset=false
|
12 | 15 | fi
|
13 | 16 |
|
14 |
| -if [[ -r "${BASH_COMPLETION:-}" ]] ; then |
15 |
| - # shellcheck disable=SC1091 |
| 17 | +if [[ -r "${BASH_COMPLETION:-}" ]]; then |
| 18 | + # shellcheck disable=SC1090 |
16 | 19 | source "${BASH_COMPLETION}"
|
17 | 20 |
|
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 |
21 | 24 |
|
22 | 25 | # 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 |
53 | 55 | fi
|
54 | 56 |
|
55 |
| -if $__bash_it_restore_nounset |
56 |
| -then |
| 57 | +if [[ ${__bash_it_restore_nounset:-false} == "true" ]]; then |
57 | 58 | shopt -so nounset
|
58 | 59 | fi
|
59 | 60 | unset __bash_it_restore_nounset
|
0 commit comments