@@ -60,10 +60,14 @@ __bp_inside_precmd=0
60
60
__bp_inside_preexec=0
61
61
62
62
# Initial PROMPT_COMMAND string that is removed from PROMPT_COMMAND post __bp_install
63
- __bp_install_string=$' __bp_trap_string="$(trap -p DEBUG)"\n trap - DEBUG\n __bp_install'
63
+ bash_preexec_install_string=$' __bp_trap_string="$(trap -p DEBUG)"\n trap - DEBUG\n __bp_install'
64
+
65
+ # WARNING: This variable is no longer used and should not be relied upon.
66
+ # Use ${bash_preexec_install_string} instead.
67
+ __bp_install_string=" ${bash_preexec_install_string} "
64
68
65
69
# The command string that is registered to the DEBUG trap.
66
- __bp_trapdebug_string =' __bp_preexec_invoke_exec "$_"'
70
+ bash_preexec_trapdebug_string =' __bp_preexec_invoke_exec "$_"'
67
71
68
72
# Fails if any of the given variables are readonly
69
73
# Reference https://stackoverflow.com/a/4441178
@@ -146,13 +150,13 @@ __bp_precmd_invoke_cmd() {
146
150
return
147
151
fi
148
152
local __bp_inside_precmd=1
149
- __bp_invoke_precmd_functions " $__bp_last_ret_value " " $__bp_last_argument_prev_command "
153
+ bash_preexec_invoke_precmd_functions " $__bp_last_ret_value " " $__bp_last_argument_prev_command "
150
154
}
151
155
152
156
# This function invokes every function defined in our function array
153
157
# "precmd_function". This function receives the arguments $1 and $2 for $? and
154
158
# $_, respectively, that will be set for the precmd functions.
155
- __bp_invoke_precmd_functions () {
159
+ bash_preexec_invoke_precmd_functions () {
156
160
local __lastexit=$1 __lastarg=$2
157
161
# Invoke every function defined in our function array.
158
162
local precmd_function
@@ -255,7 +259,7 @@ __bp_preexec_invoke_exec() {
255
259
fi
256
260
257
261
local preexec_ret_value
258
- __bp_invoke_preexec_functions " ${__bp_last_ret_value:- } " " $__bp_last_argument_prev_command " " $this_command "
262
+ bash_preexec_invoke_preexec_functions " ${__bp_last_ret_value:- } " " $__bp_last_argument_prev_command " " $this_command "
259
263
260
264
# Restore the last argument of the last executed command, and set the return
261
265
# value of the DEBUG trap to be the return code of the last preexec function
@@ -273,7 +277,7 @@ __bp_preexec_invoke_exec() {
273
277
# (corresponding to BASH_COMMAND in the DEBUG trap). This function assigns the
274
278
# last non-zero exit status from the preexec functions to the variable
275
279
# `preexec_ret_value`. If there is no error, preexec_ret_value is set to `0`.
276
- __bp_invoke_preexec_functions () {
280
+ bash_preexec_invoke_preexec_functions () {
277
281
local __lastexit=$1 __lastarg=$2 __this_command=$3
278
282
local preexec_function
279
283
local preexec_function_ret_value
@@ -300,7 +304,7 @@ __bp_install() {
300
304
return 1;
301
305
fi
302
306
303
- trap " $__bp_trapdebug_string " DEBUG
307
+ trap " $bash_preexec_trapdebug_string " DEBUG
304
308
305
309
# Preserve any prior DEBUG trap as a preexec function
306
310
local prior_trap=$( sed " s/[^']*'\(.*\)'[^']*/\1/" <<< " ${__bp_trap_string:-}" )
@@ -329,8 +333,8 @@ __bp_install() {
329
333
local existing_prompt_command
330
334
# Remove setting our trap install string and sanitize the existing prompt command string
331
335
existing_prompt_command=" ${PROMPT_COMMAND:- } "
332
- existing_prompt_command=" ${existing_prompt_command// $__bp_install_string [;$'\n']} " # Edge case of appending to PROMPT_COMMAND
333
- existing_prompt_command=" ${existing_prompt_command// $__bp_install_string } "
336
+ existing_prompt_command=" ${existing_prompt_command// $bash_preexec_install_string [;$'\n']} " # Edge case of appending to PROMPT_COMMAND
337
+ existing_prompt_command=" ${existing_prompt_command// $bash_preexec_install_string } "
334
338
__bp_sanitize_string existing_prompt_command " $existing_prompt_command "
335
339
336
340
# Install our hooks in PROMPT_COMMAND to allow our trap to know when we've
@@ -367,15 +371,15 @@ __bp_install_after_session_init() {
367
371
if [[ -n " $sanitized_prompt_command " ]]; then
368
372
PROMPT_COMMAND=${sanitized_prompt_command} $' \n '
369
373
fi ;
370
- PROMPT_COMMAND+=${__bp_install_string }
374
+ PROMPT_COMMAND+=${bash_preexec_install_string }
371
375
}
372
376
373
377
# Remove hooks installed in the DEBUG trap and PROMPT_COMMAND.
374
- __bp_uninstall () {
378
+ bash_preexec_uninstall () {
375
379
# Remove __bp_install hook from PROMPT_COMMAND
376
- if [[ ${PROMPT_COMMAND-} == * " $__bp_install_string " * ]]; then
377
- PROMPT_COMMAND=" ${PROMPT_COMMAND// $__bp_install_string [;$'\n']} " # Edge case of appending to PROMPT_COMMAND
378
- PROMPT_COMMAND=" ${PROMPT_COMMAND// $__bp_install_string } "
380
+ if [[ ${PROMPT_COMMAND-} == * " $bash_preexec_install_string " * ]]; then
381
+ PROMPT_COMMAND=" ${PROMPT_COMMAND// $bash_preexec_install_string [;$'\n']} " # Edge case of appending to PROMPT_COMMAND
382
+ PROMPT_COMMAND=" ${PROMPT_COMMAND// $bash_preexec_install_string } "
379
383
fi
380
384
381
385
# Remove precmd hook from PROMPT_COMMAND
@@ -385,15 +389,15 @@ __bp_uninstall() {
385
389
386
390
# Remove preexec hook in the DEBUG trap
387
391
local q=" '" Q=" '\''"
388
- if [[ $( trap -p DEBUG) == " trap -- '${__bp_trapdebug_string // $q / $Q } ' DEBUG" ]]; then
392
+ if [[ $( trap -p DEBUG) == " trap -- '${bash_preexec_trapdebug_string // $q / $Q } ' DEBUG" ]]; then
389
393
if [[ ${__bp_trap_string-} ]]; then
390
394
eval -- " $__bp_trap_string "
391
395
else
392
396
trap - DEBUG
393
397
fi
394
398
fi
395
399
}
396
- declare -ft __bp_uninstall
400
+ declare -ft bash_preexec_uninstall
397
401
398
402
# Run our install so long as we're not delaying it.
399
403
if [[ -z " ${__bp_delay_install:- } " ]]; then
0 commit comments