@@ -291,6 +291,15 @@ __bp_preexec_invoke_exec() {
291
291
__bp_set_ret_value " $preexec_ret_value " " $__bp_last_argument_prev_command "
292
292
}
293
293
294
+ __bp_invoke_preexec_from_ps0 () {
295
+ __bp_last_argument_prev_command=" ${1:- } "
296
+
297
+ local this_command
298
+ __bp_load_this_command_from_history || return
299
+
300
+ __bp_invoke_preexec_functions " ${__bp_last_ret_value:- } " " $__bp_last_argument_prev_command " " $this_command "
301
+ }
302
+
294
303
# This function invokes every function defined in our function array
295
304
# "preexec_function". This function receives the arguments $1 and $2 for $?
296
305
# and $_, respectively, which will be set for each preexec function. The third
@@ -320,12 +329,7 @@ __bp_invoke_preexec_functions() {
320
329
__bp_set_ret_value " $preexec_ret_value "
321
330
}
322
331
323
- __bp_install () {
324
- # Exit if we already have this installed.
325
- if [[ " ${PROMPT_COMMAND[*]:- } " == * " __bp_precmd_invoke_cmd" * ]]; then
326
- return 1
327
- fi
328
-
332
+ __bp_hook_preexec_into_debug () {
329
333
local trap_string
330
334
trap_string=$( trap -p DEBUG)
331
335
trap ' __bp_preexec_invoke_exec "$_"' DEBUG
@@ -355,6 +359,27 @@ __bp_install() {
355
359
set -o functrace > /dev/null 2>&1
356
360
shopt -s extdebug > /dev/null 2>&1
357
361
fi
362
+ }
363
+
364
+ __bp_hook_preexec_into_ps0 () {
365
+ # shellcheck disable=SC2016
366
+ PS0=${PS0-} ' ${ __bp_invoke_preexec_from_ps0 "$_"; }'
367
+
368
+ # Adjust our HISTCONTROL Variable if needed.
369
+ __bp_adjust_histcontrol
370
+ }
371
+
372
+ __bp_install () {
373
+ # Exit if we already have this installed.
374
+ if [[ " ${PROMPT_COMMAND[*]:- } " == * " __bp_precmd_invoke_cmd" * ]]; then
375
+ return 1
376
+ fi
377
+
378
+ if (( BASH_VERSINFO[0 ] > 5 || (BASH_VERSINFO[0 ] == 5 && BASH_VERSINFO[1 ] >= 3 ) )) ; then
379
+ __bp_hook_preexec_into_ps0
380
+ else
381
+ __bp_hook_preexec_into_debug
382
+ fi
358
383
359
384
local existing_prompt_command
360
385
# Remove setting our trap install string and sanitize the existing prompt command string
@@ -392,7 +417,7 @@ __bp_install() {
392
417
# Note: We need to add "trace" attribute to the function so that "trap
393
418
# ... DEBUG" inside "__bp_install" takes an effect even when there was an
394
419
# existing DEBUG trap.
395
- declare -ft __bp_install
420
+ declare -ft __bp_install __bp_hook_preexec_into_debug
396
421
397
422
# Sets an installation string as part of our PROMPT_COMMAND to install
398
423
# after our session has started. This allows bash-preexec to be included
0 commit comments