4
4
# Load the `bash-preexec.sh` library, and define helper functions
5
5
6
6
# # Prepare, load, fix, and install `bash-preexec.sh`
7
- : " ${PROMPT_COMMAND:= } "
8
7
9
- # Disable immediate `$PROMPT_COMMAND` modification
8
+ # Disable `$PROMPT_COMMAND` modification for now.
10
9
__bp_delay_install=" delayed"
11
10
12
11
# shellcheck source-path=SCRIPTDIR/../vendor/github.com/rcaloras/bash-preexec
@@ -18,12 +17,12 @@ function __bp_adjust_histcontrol() { :; }
18
17
# Don't fail on readonly variables
19
18
function __bp_require_not_readonly() { : ; }
20
19
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
24
23
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' )
27
26
28
27
# # Helper functions
29
28
function __check_precmd_conflict() {
@@ -38,26 +37,20 @@ function __check_preexec_conflict() {
38
37
_bash-it-array-contains-element " ${f} " " ${preexec_functions[@]} "
39
38
}
40
39
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
44
42
45
- if [ " ${__bp_imported:- missing} " == " defined" ]; then
43
+ if [[ " ${bash_preexec_imported :- ${ __bp_imported:- missing}} " == " defined" ] ]; then
46
44
# We are using bash-preexec
45
+ __bp_trim_whitespace f " ${1?} "
47
46
if ! __check_precmd_conflict " ${f} " ; then
48
47
precmd_functions+=(" ${f} " )
49
48
fi
50
49
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
61
54
return
62
55
elif [[ -z ${PROMPT_COMMAND} ]]; then
63
56
PROMPT_COMMAND=" ${1} "
@@ -67,12 +60,12 @@ function safe_append_prompt_command {
67
60
fi
68
61
}
69
62
70
- function safe_append_preexec {
63
+ function safe_append_preexec() {
71
64
local prompt_re f
72
- __bp_trim_whitespace f " ${1?} "
73
65
74
- if [ " ${__bp_imported:- missing} " == " defined" ]; then
66
+ if [[ " ${bash_preexec_imported :- ${ __bp_imported:- missing}} " == " defined" ] ]; then
75
67
# We are using bash-preexec
68
+ __bp_trim_whitespace f " ${1?} "
76
69
if ! __check_preexec_conflict " ${f} " ; then
77
70
preexec_functions+=(" ${f} " )
78
71
fi
0 commit comments