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