Skip to content

preexec: set options before load #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9f4c71d
Add history flushes on each command to the powerline themes.
seefood May 19, 2021
e22aac8
completion/git: expand search range
gaelicWizard Sep 25, 2021
b0750fa
completion/git: `shfmt` && `shellcheck`
gaelicWizard Sep 25, 2021
c360f0c
plugins: Add ble.sh plugin
May 21, 2021
b7feb14
skip go tests when go is not available
cornfeedhobo Sep 29, 2021
07384bc
Merge pull request #1967 from cornfeedhobo/goenv-go-tests
cornfeedhobo Sep 30, 2021
c3382c7
Merge pull request #1884 from NoahGorny/add-blesh-plugin
NoahGorny Oct 6, 2021
cf08fca
Merge pull request #1965 from gaelicWizard/completion-git
NoahGorny Oct 6, 2021
c3d333d
fix based on remarks on PR
seefood Oct 10, 2021
adab880
ci: Bump go to 1.17 from 1.14
Oct 10, 2021
49698e2
Merge pull request #1971 from NoahGorny/ci-update-go-version
NoahGorny Oct 10, 2021
d6239cf
Merge branch 'master' of https://github.com/bash-it/bash-it into ira/…
seefood Oct 11, 2021
953e422
theme/powerline: fix an oops in the last patch
gaelicWizard Oct 10, 2021
48c17e9
Merge pull request #1968 from gaelicWizard/oops
NoahGorny Oct 12, 2021
f7cc442
lib/utilities: simplify `_bash-it-array-dedup()`
gaelicWizard Oct 13, 2021
7cd0278
lib/utilities: `_bash-it-component-help()`
gaelicWizard Oct 8, 2021
413d7a1
Fix home dir substitution
zou000 Oct 17, 2021
bb3a51f
Update powerline.base.bash
zou000 Oct 17, 2021
7911f77
use `\w`
zou000 Oct 17, 2021
7987e4b
Merge pull request #1883 from seefood/ira/autosave-history-plml
NoahGorny Oct 17, 2021
b986c39
lib/utilities: XDG_CACHE_HOME
gaelicWizard Oct 12, 2021
b8ee63c
lib/utilities: quote SC2295
gaelicWizard Oct 12, 2021
253d121
lib/utilities: new function `_bash-it-egrep()`
gaelicWizard Oct 8, 2021
b0e8729
Fix save-and-reload-history command not found
krapshsa Oct 18, 2021
5feebcc
Merge pull request #1974 from zou000/patch-1
NoahGorny Oct 18, 2021
5e3810a
Merge pull request #1973 from gaelicWizard/utilities
NoahGorny Oct 18, 2021
2d1bd82
Merge pull request #1975 from krapshsa/krapshsa-patch-1
NoahGorny Oct 18, 2021
5fb69dd
preexec: set options before load
gaelicWizard Oct 18, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 0 additions & 3 deletions bash_it.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions clean_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -84,6 +85,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
Expand Down
51 changes: 27 additions & 24 deletions completion/available/git.completion.bash
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
#!/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
_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_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=(
# 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'
# 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
for _comp_path in "${_git_bash_completion_paths[@]}" ; do
if [[ -r "$_comp_path" ]] ; then
_git_bash_completion_found=true
source "$_comp_path"
break
fi
_git_bash_completion_found=false
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_paths
unset _git_bash_completion_found
unset "${!_git_bash_completion@}"
22 changes: 13 additions & 9 deletions lib/utilities.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
Expand Down Expand Up @@ -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!
Expand All @@ -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
Expand All @@ -66,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).
Expand All @@ -76,17 +81,16 @@ 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}"
}

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}"
}
Expand Down
19 changes: 19 additions & 0 deletions plugins/available/blesh.plugin.bash
Original file line number Diff line number Diff line change
@@ -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
16 changes: 9 additions & 7 deletions test/plugins/go.plugin.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions themes/powerline-multiline/powerline-multiline.base.bash
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ function __powerline_prompt_command {
SEGMENTS_AT_RIGHT=0
LAST_SEGMENT_COLOR=""

_save-and-reload-history "${HISTORY_AUTOSAVE:-0}"

## left prompt ##
for segment in $POWERLINE_LEFT_PROMPT; do
local info="$(__powerline_${segment}_prompt)"
Expand Down
2 changes: 2 additions & 0 deletions themes/powerline-naked/powerline-naked.base.bash
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ 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 {
Expand Down
6 changes: 3 additions & 3 deletions themes/powerline/powerline.base.bash
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ function __powerline_scm_prompt() {
}

function __powerline_cwd_prompt() {
local cwd="${PWD/$HOME/\~}"

echo "${cwd}|${CWD_THEME_PROMPT_COLOR}"
echo "\w|${CWD_THEME_PROMPT_COLOR}"
}

function __powerline_hostname_prompt() {
Expand Down Expand Up @@ -275,6 +273,8 @@ function __powerline_prompt_command() {
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 - -)"
fi
Expand Down
26 changes: 24 additions & 2 deletions vendor/init.d/preexec.bash
Original file line number Diff line number Diff line change
@@ -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