From e7c3263f128e0291ef9803bb114fd4038ba0911e Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 17 Sep 2021 15:57:48 -0700 Subject: [PATCH 1/3] completion/system: load earlier than other completions I chose `325` so that it's still possible to deliberately place something *before* this component, if needed somehow. --- completion/available/system.completion.bash | 5 ++++- test/install/install.bats | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/completion/available/system.completion.bash b/completion/available/system.completion.bash index 113a93f5be..aa9768ac80 100644 --- a/completion/available/system.completion.bash +++ b/completion/available/system.completion.bash @@ -1,8 +1,11 @@ -#!/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. +# Load before other completions +# BASH_IT_LOAD_PRIORITY: 325 + if shopt -qo nounset then # Bash-completion is too large and complex to expect to handle unbound variables throughout the whole codebase. __bash_it_restore_nounset=true diff --git a/test/install/install.bats b/test/install/install.bats index 40f3162d0b..b81618969a 100644 --- a/test/install/install.bats +++ b/test/install/install.bats @@ -32,7 +32,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" { From 5fab574bfd4f750371bcec602e4026ede00bd89c Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 1 Jan 2022 22:19:33 -0800 Subject: [PATCH 2/3] completion/system: `shfmt` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit My apologies to future `git blame` hunters ♥ --- clean_files.txt | 1 + completion/available/system.completion.bash | 76 ++++++++++----------- 2 files changed, 38 insertions(+), 39 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 4ecda78745..237cb95bd4 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -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 diff --git a/completion/available/system.completion.bash b/completion/available/system.completion.bash index aa9768ac80..af7ea70dc0 100644 --- a/completion/available/system.completion.bash +++ b/completion/available/system.completion.bash @@ -6,57 +6,55 @@ # Load before other completions # BASH_IT_LOAD_PRIORITY: 325 -if shopt -qo nounset -then # Bash-completion is too large and complex to expect to handle unbound variables throughout the whole codebase. +# 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 From 04c7424de5c0bdcfc87d28ad83121ee26d32f4da Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 3 Jan 2022 08:22:33 -0800 Subject: [PATCH 3/3] completion/system: fix tests for `profile` command --- test/lib/helpers.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index d876d882fa..c10716a5cb 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -303,7 +303,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" { @@ -363,7 +363,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" {