From 9f4c71d40ff987eca27d53eabbe5c385c018cb9f Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Wed, 19 May 2021 10:54:28 +0300 Subject: [PATCH 01/18] Add history flushes on each command to the powerline themes. --- themes/powerline-multiline/powerline-multiline.base.bash | 1 + themes/powerline-naked/powerline-naked.base.bash | 1 + themes/powerline/powerline.base.bash | 1 + 3 files changed, 3 insertions(+) diff --git a/themes/powerline-multiline/powerline-multiline.base.bash b/themes/powerline-multiline/powerline-multiline.base.bash index 7ae33f8638..33a8c398e3 100644 --- a/themes/powerline-multiline/powerline-multiline.base.bash +++ b/themes/powerline-multiline/powerline-multiline.base.bash @@ -60,6 +60,7 @@ function __powerline_prompt_command { SEGMENTS_AT_LEFT=0 SEGMENTS_AT_RIGHT=0 LAST_SEGMENT_COLOR="" + _save-and-reload-history "${HISTORY_AUTOSAVE:-0}" ## left prompt ## for segment in $POWERLINE_LEFT_PROMPT; do diff --git a/themes/powerline-naked/powerline-naked.base.bash b/themes/powerline-naked/powerline-naked.base.bash index 16b633be9f..98686075bd 100644 --- a/themes/powerline-naked/powerline-naked.base.bash +++ b/themes/powerline-naked/powerline-naked.base.bash @@ -26,6 +26,7 @@ function __powerline_left_segment { LEFT_PROMPT+="$(set_color ${params[1]} -)${pad_before_segment}${params[0]}${normal}" LAST_SEGMENT_COLOR=${params[1]} (( SEGMENTS_AT_LEFT += 1 )) + _save-and-reload-history "${HISTORY_AUTOSAVE:-0}" } function __powerline_left_last_segment_padding { diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index 43ee8be113..ed0499c7f6 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -255,6 +255,7 @@ function __powerline_prompt_command() { LEFT_PROMPT="" SEGMENTS_AT_LEFT=0 LAST_SEGMENT_COLOR="" + save-and-reload-history "${HISTORY_AUTOSAVE:-0}" if [[ -n "${POWERLINE_PROMPT_DISTRO_LOGO}" ]]; then LEFT_PROMPT+="$(set_color "${PROMPT_DISTRO_LOGO_COLOR}" "${PROMPT_DISTRO_LOGO_COLORBG}")${PROMPT_DISTRO_LOGO}$(set_color - -)" From e22aac855ef7bf2b9d09f086d64df272bdd23d1b Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 24 Sep 2021 21:10:01 -0700 Subject: [PATCH 02/18] completion/git: expand search range - Remove limitation on OS. - Add search for Mac OS X developer tools locations by using `xcrun` instead of trying to guess paths. - Add search for locations based on path of `$GIT_EXE` (set by `lib/theme`). --- completion/available/git.completion.bash | 30 +++++++++++++----------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/completion/available/git.completion.bash b/completion/available/git.completion.bash index b9bb1bb63e..16b21f2cf2 100644 --- a/completion/available/git.completion.bash +++ b/completion/available/git.completion.bash @@ -1,28 +1,31 @@ -#!/usr/bin/env bash - -# Only operate on MacOS since there are no linux paths -if [[ "$OSTYPE" != 'darwin'* ]] ; then - _log_warning "unsupported operating system - only 'Darwin' is supported" - return 0 -fi +# shellcheck shell=bash +# +# Locate and load completions for `git`. # Make sure git is installed -_command_exists git || return 0 +_command_exists git || return # Don't handle completion if it's already managed -if complete -p git &>/dev/null ; then +if complete -p git &>/dev/null; then _log_warning "completion already loaded - this usually means it is safe to stop using this completion" return 0 fi -_git_bash_completion_found=false +_git_bash_completion_xcrun_git= +if _command_exists xcrun; then + _git_bash_completion_xcrun_git="$(xcrun --find git)" +fi _git_bash_completion_paths=( + # Standard locations + "${GIT_EXE%/*}/../share/git-core/git-completion.bash" + "${GIT_EXE%/*}/../share/git-core/contrib/completion/git-completion.bash" + "${GIT_EXE%/*}/../etc/bash_completion.d/git-completion.bash" # MacOS non-system locations - '/Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash' - '/Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash' + "${_git_bash_completion_xcrun_git%/bin/git}/share/git-core/git-completion.bash" ) # Load the first completion file found +_git_bash_completion_found=false for _comp_path in "${_git_bash_completion_paths[@]}" ; do if [[ -r "$_comp_path" ]] ; then _git_bash_completion_found=true @@ -35,5 +38,4 @@ done if [[ "${_git_bash_completion_found}" == false ]]; then _log_warning "no completion files found - please try enabling the 'system' completion instead." fi -unset _git_bash_completion_paths -unset _git_bash_completion_found +unset "${!_git_bash_completion@}" From b0750fa49fcdc4fe102ea6b907c3a7b9ac0518a3 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 24 Sep 2021 21:10:32 -0700 Subject: [PATCH 03/18] completion/git: `shfmt` && `shellcheck` --- clean_files.txt | 1 + completion/available/git.completion.bash | 33 ++++++++++++------------ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 2242ef5ea4..cff2c60b11 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -49,6 +49,7 @@ completion/available/docker-machine.completion.bash completion/available/docker.completion.bash completion/available/gcloud.completion.bash completion/available/gem.completion.bash +completion/available/git.completion.bash completion/available/github-cli.completion.bash completion/available/go.completion.bash completion/available/helm.completion.bash diff --git a/completion/available/git.completion.bash b/completion/available/git.completion.bash index 16b21f2cf2..31b77fa3de 100644 --- a/completion/available/git.completion.bash +++ b/completion/available/git.completion.bash @@ -6,9 +6,9 @@ _command_exists git || return # Don't handle completion if it's already managed -if complete -p git &>/dev/null; then - _log_warning "completion already loaded - this usually means it is safe to stop using this completion" - return 0 +if complete -p git &> /dev/null; then + _log_warning "completion already loaded - this usually means it is safe to stop using this completion" + return 0 fi _git_bash_completion_xcrun_git= @@ -16,26 +16,27 @@ if _command_exists xcrun; then _git_bash_completion_xcrun_git="$(xcrun --find git)" fi _git_bash_completion_paths=( - # Standard locations - "${GIT_EXE%/*}/../share/git-core/git-completion.bash" - "${GIT_EXE%/*}/../share/git-core/contrib/completion/git-completion.bash" - "${GIT_EXE%/*}/../etc/bash_completion.d/git-completion.bash" - # MacOS non-system locations - "${_git_bash_completion_xcrun_git%/bin/git}/share/git-core/git-completion.bash" + # Standard locations + "${GIT_EXE%/*}/../share/git-core/git-completion.bash" + "${GIT_EXE%/*}/../share/git-core/contrib/completion/git-completion.bash" + "${GIT_EXE%/*}/../etc/bash_completion.d/git-completion.bash" + # MacOS non-system locations + "${_git_bash_completion_xcrun_git%/bin/git}/share/git-core/git-completion.bash" ) # Load the first completion file found _git_bash_completion_found=false -for _comp_path in "${_git_bash_completion_paths[@]}" ; do - if [[ -r "$_comp_path" ]] ; then - _git_bash_completion_found=true - source "$_comp_path" - break - fi +for _comp_path in "${_git_bash_completion_paths[@]}"; do + if [[ -r "$_comp_path" ]]; then + _git_bash_completion_found=true + # shellcheck disable=SC1090 # don't follow + source "$_comp_path" + break + fi done # Cleanup if [[ "${_git_bash_completion_found}" == false ]]; then - _log_warning "no completion files found - please try enabling the 'system' completion instead." + _log_warning "no completion files found - please try enabling the 'system' completion instead." fi unset "${!_git_bash_completion@}" From c360f0c7c5c30dfbd0f19e451bb101cfac4196a5 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Fri, 21 May 2021 17:47:44 +0300 Subject: [PATCH 04/18] plugins: Add ble.sh plugin --- clean_files.txt | 1 + plugins/available/blesh.plugin.bash | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 plugins/available/blesh.plugin.bash diff --git a/clean_files.txt b/clean_files.txt index 420c6cc934..da7e41bcc5 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -84,6 +84,7 @@ plugins/available/alias-completion.plugin.bash plugins/available/autojump.plugin.bash plugins/available/base.plugin.bash plugins/available/basher.plugin.bash +plugins/available/blesh.plugin.bash plugins/available/cmd-returned-notify.plugin.bash plugins/available/direnv.plugin.bash plugins/available/docker-machine.plugin.bash diff --git a/plugins/available/blesh.plugin.bash b/plugins/available/blesh.plugin.bash new file mode 100644 index 0000000000..7b1ce74e68 --- /dev/null +++ b/plugins/available/blesh.plugin.bash @@ -0,0 +1,19 @@ +# shellcheck shell=bash +cite about-plugin +about-plugin 'load ble.sh, the Bash line editor!' + +if [[ ${BLE_VERSION-} ]]; then + _log_warning "ble.sh is already loaded!" + return +fi + +_bash_it_ble_path=${XDG_DATA_HOME:-$HOME/.local/share}/blesh/ble.sh +if [[ -f $_bash_it_ble_path ]]; then + # shellcheck disable=1090 + source "$_bash_it_ble_path" +else + _log_error "Could not find ble.sh in $_bash_it_ble_path" + _log_error "Please install using the following command:" + _log_error "git clone https://github.com/akinomyoga/ble.sh && make -C ble.sh install" +fi +unset _bash_it_ble_path From b7feb144041168607d640aa9c9e8c514531f538a Mon Sep 17 00:00:00 2001 From: cornfeedhobo Date: Wed, 29 Sep 2021 18:06:42 -0500 Subject: [PATCH 05/18] skip go tests when go is not available --- test/plugins/go.plugin.bats | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/test/plugins/go.plugin.bats b/test/plugins/go.plugin.bats index c53f359f1f..110699e898 100644 --- a/test/plugins/go.plugin.bats +++ b/test/plugins/go.plugin.bats @@ -4,50 +4,52 @@ load ../test_helper load ../../lib/helpers load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" +# We test `go version` in each test to account for users with goenv and no system go. + @test 'ensure _bash-it-gopath-pathmunge is defined' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' + { _command_exists go && go version &>/dev/null; } || skip 'golang not found' load ../../plugins/available/go.plugin run type -t _bash-it-gopath-pathmunge assert_line 'function' } @test 'plugins go: single entry in GOPATH' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' + { _command_exists go && go version &>/dev/null; } || skip 'golang not found' export GOPATH="/foo" load ../../plugins/available/go.plugin assert_equal "$(cut -d':' -f1 <<<$PATH)" "/foo/bin" } @test 'plugins go: single entry in GOPATH, with space' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' + { _command_exists go && go version &>/dev/null; } || skip 'golang not found' export GOPATH="/foo bar" load ../../plugins/available/go.plugin assert_equal "$(cut -d':' -f1 <<<$PATH)" "/foo bar/bin" } @test 'plugins go: single entry in GOPATH, with escaped space' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' + { _command_exists go && go version &>/dev/null; } || skip 'golang not found' export GOPATH="/foo\ bar" load ../../plugins/available/go.plugin assert_equal "$(cut -d':' -f1 <<<$PATH)" "/foo\ bar/bin" } @test 'plugins go: multiple entries in GOPATH' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' + { _command_exists go && go version &>/dev/null; } || skip 'golang not found' export GOPATH="/foo:/bar" load ../../plugins/available/go.plugin assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo/bin:/bar/bin" } @test 'plugins go: multiple entries in GOPATH, with space' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' + { _command_exists go && go version &>/dev/null; } || skip 'golang not found' export GOPATH="/foo:/foo bar" load ../../plugins/available/go.plugin assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo/bin:/foo bar/bin" } @test 'plugins go: multiple entries in GOPATH, with escaped space' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' + { _command_exists go && go version &>/dev/null; } || skip 'golang not found' export GOPATH="/foo:/foo\ bar" load ../../plugins/available/go.plugin assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo/bin:/foo\ bar/bin" From c3d333ddc4f369806162b2cdf8ce1e321b1c413f Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Sun, 10 Oct 2021 15:25:45 +0300 Subject: [PATCH 06/18] fix based on remarks on PR --- themes/powerline-multiline/powerline-multiline.base.bash | 1 + themes/powerline-naked/powerline-naked.base.bash | 1 + themes/powerline/powerline.base.bash | 1 + 3 files changed, 3 insertions(+) diff --git a/themes/powerline-multiline/powerline-multiline.base.bash b/themes/powerline-multiline/powerline-multiline.base.bash index 33a8c398e3..f752bd7516 100644 --- a/themes/powerline-multiline/powerline-multiline.base.bash +++ b/themes/powerline-multiline/powerline-multiline.base.bash @@ -60,6 +60,7 @@ function __powerline_prompt_command { SEGMENTS_AT_LEFT=0 SEGMENTS_AT_RIGHT=0 LAST_SEGMENT_COLOR="" + _save-and-reload-history "${HISTORY_AUTOSAVE:-0}" ## left prompt ## diff --git a/themes/powerline-naked/powerline-naked.base.bash b/themes/powerline-naked/powerline-naked.base.bash index 98686075bd..dfc63f7640 100644 --- a/themes/powerline-naked/powerline-naked.base.bash +++ b/themes/powerline-naked/powerline-naked.base.bash @@ -26,6 +26,7 @@ function __powerline_left_segment { LEFT_PROMPT+="$(set_color ${params[1]} -)${pad_before_segment}${params[0]}${normal}" LAST_SEGMENT_COLOR=${params[1]} (( SEGMENTS_AT_LEFT += 1 )) + _save-and-reload-history "${HISTORY_AUTOSAVE:-0}" } diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index ed0499c7f6..ce62870329 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -255,6 +255,7 @@ function __powerline_prompt_command() { LEFT_PROMPT="" SEGMENTS_AT_LEFT=0 LAST_SEGMENT_COLOR="" + save-and-reload-history "${HISTORY_AUTOSAVE:-0}" if [[ -n "${POWERLINE_PROMPT_DISTRO_LOGO}" ]]; then From adab880f89aa0cf5bd4c24071c642a386dbd4c82 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Sun, 10 Oct 2021 23:50:39 +0300 Subject: [PATCH 07/18] ci: Bump go to 1.17 from 1.14 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f42c096b6c..3c7ba2aeed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,7 +45,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: 1.14 + go-version: 1.17 - name: Set up Python uses: actions/setup-python@v2 with: From 953e422bed2f9b0ba01ec998fe619e523819551f Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 9 Oct 2021 21:06:31 -0700 Subject: [PATCH 08/18] theme/powerline: fix an oops in the last patch The tilde should not have been escaped, and in fact I did not have it escaped in my main branch, but the PR I submitted did have it escaped and...now it shows up in the prompt line for all the PowerLine themes... oops. --- themes/powerline/powerline.base.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index ade3670da2..cffaa98d99 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -142,7 +142,7 @@ function __powerline_scm_prompt() { } function __powerline_cwd_prompt() { - local cwd="${PWD/$HOME/\~}" + local cwd="${PWD/$HOME/~}" echo "${cwd}|${CWD_THEME_PROMPT_COLOR}" } From f7cc442af4439d2156b60bc9846cb299dadae687 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 13 Oct 2021 09:27:55 -0700 Subject: [PATCH 09/18] lib/utilities: simplify `_bash-it-array-dedup()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit alsö fix usage example of `_bash-it-array-contains-element()` --- lib/utilities.bash | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/utilities.bash b/lib/utilities.bash index 84fa4d96b2..9b011910f2 100644 --- a/lib/utilities.bash +++ b/lib/utilities.bash @@ -40,7 +40,7 @@ function _bash-it-get-component-type-from-path() { # $ _bash-it-array-contains-element apple "@{fruits[@]}" && echo 'contains apple' # contains apple # -# $ if $(_bash-it-array-contains-element pear "${fruits[@]}"); then +# $ if _bash-it-array-contains-element pear "${fruits[@]}"; then # echo "contains pear!" # fi # contains pear! @@ -54,10 +54,9 @@ function _bash-it-array-contains-element() { return 1 } -# Dedupe a simple array of words without spaces. +# Dedupe an array (without embedded newlines). function _bash-it-array-dedup() { - local IFS=$'\n' - echo "$@" | tr ' ' '\n' | sort -u + printf '%s\n' "$@" | sort -u } # Outputs a full path of the grep found on the filesystem From 7cd02781f8df8af55dc0e7c6127f624c3ea34373 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 7 Oct 2021 22:43:48 -0700 Subject: [PATCH 10/18] lib/utilities: `_bash-it-component-help()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No need to `rm` when we overwrite the file the line after next. Alsö, use `>|` in case the user sets `noclobber`; we do expressly intend to overwrite the file in this case. --- lib/utilities.bash | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/utilities.bash b/lib/utilities.bash index 9b011910f2..a6701fff1b 100644 --- a/lib/utilities.bash +++ b/lib/utilities.bash @@ -75,9 +75,8 @@ function _bash-it-component-help() { component="$(_bash-it-pluralize-component "${1}")" file="$(_bash-it-component-cache-file "${component}")" if [[ ! -s "${file}" || -z "$(find "${file}" -mmin -300)" ]]; then - rm -f "${file}" 2> /dev/null func="_bash-it-${component}" - "${func}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E ' \[' > "${file}" + "${func}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E ' \[' >| "${file}" fi cat "${file}" } From 413d7a1326721ce803240fc5af299329e2afee3c Mon Sep 17 00:00:00 2001 From: zou000 Date: Sat, 16 Oct 2021 19:15:00 -0700 Subject: [PATCH 11/18] Fix home dir substitution See the discussions in https://github.com/Bash-it/bash-it/commit/953e422bed2f9b0ba01ec998fe619e523819551f#commitcomment-58148656 . Tested with bash 5.1 and bash 3.2 --- themes/powerline/powerline.base.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index cffaa98d99..db770404aa 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -142,7 +142,7 @@ function __powerline_scm_prompt() { } function __powerline_cwd_prompt() { - local cwd="${PWD/$HOME/~}" + local cwd=${PWD/$HOME/\~} echo "${cwd}|${CWD_THEME_PROMPT_COLOR}" } From bb3a51f742b610b4ffe1a2fb020b2de3504df17b Mon Sep 17 00:00:00 2001 From: zou000 Date: Sat, 16 Oct 2021 20:24:07 -0700 Subject: [PATCH 12/18] Update powerline.base.bash --- themes/powerline/powerline.base.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index db770404aa..3a44307dc4 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -142,7 +142,8 @@ function __powerline_scm_prompt() { } function __powerline_cwd_prompt() { - local cwd=${PWD/$HOME/\~} + # For maximum backwards compatibility: no outer quotes, escape ~ + local cwd=${PWD/#$HOME/\~} echo "${cwd}|${CWD_THEME_PROMPT_COLOR}" } From 7911f770cf9d7d9ca554251b2516497f08571303 Mon Sep 17 00:00:00 2001 From: zou000 Date: Sat, 16 Oct 2021 22:29:25 -0700 Subject: [PATCH 13/18] use `\w` --- themes/powerline/powerline.base.bash | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index 3a44307dc4..5e07d36d37 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -142,10 +142,7 @@ function __powerline_scm_prompt() { } function __powerline_cwd_prompt() { - # For maximum backwards compatibility: no outer quotes, escape ~ - local cwd=${PWD/#$HOME/\~} - - echo "${cwd}|${CWD_THEME_PROMPT_COLOR}" + echo "\w|${CWD_THEME_PROMPT_COLOR}" } function __powerline_hostname_prompt() { From b986c390401f36b44630576e87551f6a84fb1e17 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Tue, 12 Oct 2021 13:16:28 -0700 Subject: [PATCH 14/18] lib/utilities: XDG_CACHE_HOME Use $XDG_CACHE_HOME environment constant instead of placing a tmp/cache folder inside the bash-it data repo. If not defined, fall back to current behavior. This resolves Bash-It/Bash-It#1904. --- lib/utilities.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/utilities.bash b/lib/utilities.bash index a6701fff1b..3ceda5f16f 100644 --- a/lib/utilities.bash +++ b/lib/utilities.bash @@ -83,8 +83,8 @@ function _bash-it-component-help() { function _bash-it-component-cache-file() { local component file - component="$(_bash-it-pluralize-component "${1}")" - file="${BASH_IT?}/tmp/cache/${component}" + component="$(_bash-it-pluralize-component "${1?${FUNCNAME[0]}: component name required}")" + file="${XDG_CACHE_HOME:-${BASH_IT?}/tmp/cache}${XDG_CACHE_HOME:+/bash_it}/${component}" [[ -f "${file}" ]] || mkdir -p "${file%/*}" printf '%s' "${file}" } From b8ee63c67d1be89c9abf9e330b5b63f79328e104 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Tue, 12 Oct 2021 10:58:49 -0700 Subject: [PATCH 15/18] lib/utilities: quote SC2295 Doesn't show up on my shellcheck 0.7.2, but does for NoahGorny! --- lib/utilities.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utilities.bash b/lib/utilities.bash index 3ceda5f16f..52c4877682 100644 --- a/lib/utilities.bash +++ b/lib/utilities.bash @@ -11,7 +11,7 @@ function _bash-it-get-component-name-from-path() { # filename without path filename="${1##*/}" # filename without path or priority - filename="${filename##*${BASH_IT_LOAD_PRIORITY_SEPARATOR?}}" + filename="${filename##*"${BASH_IT_LOAD_PRIORITY_SEPARATOR?}"}" # filename without path, priority or extension echo "${filename%.*.bash}" } From 253d1213e07ad33cfadd12fe3cff128e4b22cfb8 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 7 Oct 2021 22:39:49 -0700 Subject: [PATCH 16/18] lib/utilities: new function `_bash-it-egrep()` The existing function `_bash-it-grep()` is weird. New function `_bash-it-egrep()` just does the thing without requiring two subshells and manual invocation. --- lib/utilities.bash | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/utilities.bash b/lib/utilities.bash index 52c4877682..1f249b98f4 100644 --- a/lib/utilities.bash +++ b/lib/utilities.bash @@ -65,6 +65,12 @@ function _bash-it-grep() { printf "%s" "${BASH_IT_GREP:-'/usr/bin/grep'}" } +# Runs `grep` with extended regular expressions +function _bash-it-egrep() { + : "${BASH_IT_GREP:=$(type -p egrep || type -p grep)}" + "${BASH_IT_GREP:-/usr/bin/grep}" -E "$@" +} + ########################################################################### # Component-specific functions (component is either an alias, a plugin, or a # completion). From b0e8729b0f76979239cebd982b9cd32c7a622af4 Mon Sep 17 00:00:00 2001 From: krapshsa Date: Tue, 19 Oct 2021 00:58:01 +0800 Subject: [PATCH 17/18] Fix save-and-reload-history command not found --- themes/powerline/powerline.base.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index b93431f5e0..9f55e645f7 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -275,7 +275,7 @@ function __powerline_prompt_command() { SEGMENTS_AT_LEFT=0 LAST_SEGMENT_COLOR="" - save-and-reload-history "${HISTORY_AUTOSAVE:-0}" + _save-and-reload-history "${HISTORY_AUTOSAVE:-0}" if [[ -n "${POWERLINE_PROMPT_DISTRO_LOGO}" ]]; then LEFT_PROMPT+="$(set_color "${PROMPT_DISTRO_LOGO_COLOR}" "${PROMPT_DISTRO_LOGO_COLORBG}")${PROMPT_DISTRO_LOGO}$(set_color - -)" From 5fb69ddd4daec955580bc335509b7b182fabd763 Mon Sep 17 00:00:00 2001 From: John D Pell <52194+gaelicWizard@users.noreply.github.com> Date: Mon, 18 Oct 2021 12:00:36 -0400 Subject: [PATCH 18/18] preexec: set options before load By setting `__bp_delay_install`, we avoid any immediate initialization at all. We then override two troublesome functions before calling `__bp_install_after_session_init()`. The `__bp_install_after_session_init()` function doesn't enable the DEBUG trap, just sets `$PROMPT_COMMAND` to include `__bp_install()`, so the actual final `$PROMPT_COMMAND` is not finished, and DEBUG trap set, until after the first prompt is displayed. --- bash_it.sh | 3 --- vendor/init.d/preexec.bash | 26 ++++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/bash_it.sh b/bash_it.sh index 215c33c7db..de655e81c6 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -155,6 +155,3 @@ if ! _command_exists reload && [[ -n "${BASH_IT_RELOAD_LEGACY:-}" ]]; then ;; esac fi - -# Disable trap DEBUG on subshells - https://github.com/Bash-it/bash-it/pull/1040 -set +T diff --git a/vendor/init.d/preexec.bash b/vendor/init.d/preexec.bash index 296b478af6..01a6007b7e 100644 --- a/vendor/init.d/preexec.bash +++ b/vendor/init.d/preexec.bash @@ -1,3 +1,25 @@ # shellcheck shell=bash -# shellcheck disable=1090 -source "${BASH_IT}"/vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh +# shellcheck disable=SC2034 +# +# Load the `bash-preexec.sh` library, and define helper functions + +## Prepare, load, fix, and install `bash-preexec.sh` + +# Disable immediate `$PROMPT_COMMAND` modification +__bp_delay_install="delayed" + +# shellcheck source-path=SCRIPTDIR/vendor/github.com/rcaloras/bash-preexec +source "${BASH_IT?}/vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh" + +# Block damanaging user's `$HISTCONTROL` +function __bp_adjust_histcontrol() { :; } + +# Don't fail on readonly variables +function __bp_require_not_readonly() { :; } + +# Disable trap DEBUG on subshells - https://github.com/Bash-it/bash-it/pull/1040 +__bp_enable_subshells= # blank +set +T + +# Modify `$PROMPT_COMMAND` now +__bp_install_after_session_init