Skip to content

Commit 33bade2

Browse files
authored
Merge pull request #2073 from gaelicWizard/lib/preexec
Update "preexec" from "https://github.com/rcaloras/bash-preexec@master"
2 parents 1c8ad2c + 8246794 commit 33bade2

File tree

2 files changed

+38
-35
lines changed

2 files changed

+38
-35
lines changed

lib/preexec.bash

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
# Load the `bash-preexec.sh` library, and define helper functions
55

66
## Prepare, load, fix, and install `bash-preexec.sh`
7-
: "${PROMPT_COMMAND:=}"
87

9-
# Disable immediate `$PROMPT_COMMAND` modification
8+
# Disable `$PROMPT_COMMAND` modification for now.
109
__bp_delay_install="delayed"
1110

1211
# shellcheck source-path=SCRIPTDIR/../vendor/github.com/rcaloras/bash-preexec
@@ -18,12 +17,12 @@ function __bp_adjust_histcontrol() { :; }
1817
# Don't fail on readonly variables
1918
function __bp_require_not_readonly() { :; }
2019

21-
# Disable trap DEBUG on subshells - https://github.com/Bash-it/bash-it/pull/1040
22-
__bp_enable_subshells= # blank
23-
set +T
20+
# For performance, testing, and to avoid unexpected behavior: disable DEBUG traps in subshells.
21+
# See bash-it/bash-it#1040 and rcaloras/bash-preexec#26
22+
: "${__bp_enable_subshells:=}" # blank
2423

25-
# Modify `$PROMPT_COMMAND` now
26-
__bp_install_after_session_init
24+
# Modify `$PROMPT_COMMAND` in finalize hook
25+
_bash_it_library_finalize_hook+=('__bp_install_after_session_init')
2726

2827
## Helper functions
2928
function __check_precmd_conflict() {
@@ -38,26 +37,20 @@ function __check_preexec_conflict() {
3837
_bash-it-array-contains-element "${f}" "${preexec_functions[@]}"
3938
}
4039

41-
function safe_append_prompt_command {
42-
local prompt_re f
43-
__bp_trim_whitespace f "${1?}"
40+
function safe_append_prompt_command() {
41+
local prompt_re prompt_er f
4442

45-
if [ "${__bp_imported:-missing}" == "defined" ]; then
43+
if [[ "${bash_preexec_imported:-${__bp_imported:-missing}}" == "defined" ]]; then
4644
# We are using bash-preexec
45+
__bp_trim_whitespace f "${1?}"
4746
if ! __check_precmd_conflict "${f}"; then
4847
precmd_functions+=("${f}")
4948
fi
5049
else
51-
# Set OS dependent exact match regular expression
52-
if [[ ${OSTYPE} == darwin* ]]; then
53-
# macOS
54-
prompt_re="[[:<:]]${1}[[:>:]]"
55-
else
56-
# Linux, FreeBSD, etc.
57-
prompt_re="\<${1}\>"
58-
fi
59-
60-
if [[ ${PROMPT_COMMAND} =~ ${prompt_re} ]]; then
50+
# Match on word-boundaries
51+
prompt_re='(^|[^[:alnum:]_])'
52+
prompt_er='([^[:alnum:]_]|$)'
53+
if [[ ${PROMPT_COMMAND} =~ ${prompt_re}"${1}"${prompt_er} ]]; then
6154
return
6255
elif [[ -z ${PROMPT_COMMAND} ]]; then
6356
PROMPT_COMMAND="${1}"
@@ -67,12 +60,12 @@ function safe_append_prompt_command {
6760
fi
6861
}
6962

70-
function safe_append_preexec {
63+
function safe_append_preexec() {
7164
local prompt_re f
72-
__bp_trim_whitespace f "${1?}"
7365

74-
if [ "${__bp_imported:-missing}" == "defined" ]; then
66+
if [[ "${bash_preexec_imported:-${__bp_imported:-missing}}" == "defined" ]]; then
7567
# We are using bash-preexec
68+
__bp_trim_whitespace f "${1?}"
7669
if ! __check_preexec_conflict "${f}"; then
7770
preexec_functions+=("${f}")
7871
fi

vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh

Lines changed: 21 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)