From 43947e2cbc247634e9129bd193a0a08a7e0d316e Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 26 Jul 2021 13:04:53 -0700 Subject: [PATCH 1/2] completion/system: prefer direct invocation Instead of using the profile.d version, just invoke the script. The profile.d script preemptively short-circuits if it thinks that bash-completions has already been loaded, which it does by using the $BASH_COMPLETION variable, which is expressly supported by upstream to specify the location of the script...so it will entirely be never loaded if this is set. --- completion/available/system.completion.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) mode change 100644 => 100755 completion/available/system.completion.bash diff --git a/completion/available/system.completion.bash b/completion/available/system.completion.bash old mode 100644 new mode 100755 index 8c4f71dc..2fe9b210 --- a/completion/available/system.completion.bash +++ b/completion/available/system.completion.bash @@ -14,12 +14,12 @@ elif [[ -r /etc/profile.d/bash_completion.sh ]] ; then fi -if [[ "$(uname -s)" == 'Darwin' ]] && _command_exists brew ; then +if [[ $OSTYPE == 'darwin'* ]] && _command_exists brew ; then BREW_PREFIX=${BREW_PREFIX:-$(brew --prefix)} # homebrew/versions/bash-completion2 (required for projects.completion.bash) is installed to this path - if [[ -r "$BREW_PREFIX"/etc/profile.d/bash_completion.sh ]] ; then + if [[ -r "$BREW_PREFIX"/etc/bash_completion ]] ; then # shellcheck disable=SC1090 - source "$BREW_PREFIX"/etc/profile.d/bash_completion.sh + source "$BREW_PREFIX"/etc/bash_completion fi fi From 893c8dbb96b0a1a6d2bf0ad6a7f9218a66598f44 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 26 Jul 2021 13:09:08 -0700 Subject: [PATCH 2/2] completion/system: support $BASH_COMPLETION MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bash-completion supports pre-defining $BASH_COMPLETION as the path to the main script, so use that if it's defined. Alsö, don't load homebrew's completion if we've successfully loaded one already. --- completion/available/system.completion.bash | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/completion/available/system.completion.bash b/completion/available/system.completion.bash index 2fe9b210..b64fb82b 100755 --- a/completion/available/system.completion.bash +++ b/completion/available/system.completion.bash @@ -1,9 +1,11 @@ #!/usr/bin/env bash - +# # Loads the system's Bash completion modules. # If Homebrew is installed (OS X), it's Bash completion modules are loaded. -if [[ -r /etc/bash_completion ]] ; then +if [[ -r "${BASH_COMPLETION:-}" ]] ; then + source "${BASH_COMPLETION}" +elif [[ -r /etc/bash_completion ]] ; then # shellcheck disable=SC1091 source /etc/bash_completion @@ -12,9 +14,7 @@ elif [[ -r /etc/profile.d/bash_completion.sh ]] ; then # shellcheck disable=SC1091 source /etc/profile.d/bash_completion.sh -fi - -if [[ $OSTYPE == 'darwin'* ]] && _command_exists brew ; then +elif [[ $OSTYPE == 'darwin'* ]] && _command_exists brew ; then BREW_PREFIX=${BREW_PREFIX:-$(brew --prefix)} # homebrew/versions/bash-completion2 (required for projects.completion.bash) is installed to this path