@@ -71,7 +71,7 @@ __bp_inside_precmd=0
71
71
__bp_inside_preexec=0
72
72
73
73
# Initial PROMPT_COMMAND string that is removed from PROMPT_COMMAND post __bp_install
74
- __bp_install_string=$' __bp_trap_string="$(trap -p DEBUG)" \n trap - DEBUG \n __bp_install '
74
+ __bp_install_string=' __bp_install '
75
75
76
76
# Fails if any of the given variables are readonly
77
77
# Reference https://stackoverflow.com/a/4441178
@@ -326,14 +326,15 @@ __bp_install() {
326
326
return 1
327
327
fi
328
328
329
+ local trap_string
330
+ trap_string=$( trap -p DEBUG)
329
331
trap ' __bp_preexec_invoke_exec "$_"' DEBUG
330
332
331
333
# Preserve any prior DEBUG trap as a preexec function
332
334
local prior_trap
333
335
# we can't easily do this with variable expansion. Leaving as sed command.
334
336
# shellcheck disable=SC2001
335
- prior_trap=$( sed " s/[^']*'\(.*\)'[^']*/\1/" <<< " ${__bp_trap_string:-}" )
336
- unset __bp_trap_string
337
+ prior_trap=$( sed " s/[^']*'\(.*\)'[^']*/\1/" <<< " ${trap_string:-}" )
337
338
if [[ -n " $prior_trap " ]]; then
338
339
eval ' __bp_original_debug_trap() {
339
340
' " $prior_trap " '
@@ -388,6 +389,11 @@ __bp_install() {
388
389
__bp_interactive_mode
389
390
}
390
391
392
+ # Note: We need to add "trace" attribute to the function so that "trap
393
+ # ... DEBUG" inside "__bp_install" takes an effect even when there was an
394
+ # existing DEBUG trap.
395
+ declare -ft __bp_install
396
+
391
397
# Sets an installation string as part of our PROMPT_COMMAND to install
392
398
# after our session has started. This allows bash-preexec to be included
393
399
# at any point in our bash profile.
0 commit comments