From 321d74e6e70c5ce9777db9f473a412015bd6a8f0 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Tue, 27 Jul 2021 18:36:23 -0700 Subject: [PATCH] Use $BASH_COMMAND if HISTCONTROL is incompatible When determining the command line, check if `$HISTCONTROL` is configured as expected. If not, then fall back to the built-in variable `$BASH_COMMAND` for a second-best command line. This accounts for when the user either changes `$HISTCONTROL` after loading `bash-preexec`, or otherwise removes/disables `__bp_adjust_histcontrol`. --- bash-preexec.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bash-preexec.sh b/bash-preexec.sh index 8eb2f86..e07c081 100644 --- a/bash-preexec.sh +++ b/bash-preexec.sh @@ -81,7 +81,7 @@ __bp_adjust_histcontrol() { histcontrol="ignoredups:${histcontrol//ignoreboth}" fi; - if [[ -z "${__bp_suppress_histcontrol_warning:-}" && "$HISTCONTROL" == *ignore+(dups|space)* ]] + if [[ -z "${__bp_suppress_histcontrol_warning:-}" && "$HISTCONTROL" == *ignore+(both|space)* ]] then echo "bash-preexec is unable to determine full command line when \$HISTCONTROL contains 'ignorespace' (or 'ignoreboth')." >&2 echo "Those options have been removed from \$HISTCONTROL." >&2 @@ -232,10 +232,12 @@ __bp_preexec_invoke_exec() { fi local this_command - this_command=$( - export LC_ALL=C - HISTTIMEFORMAT= builtin history 1 | sed '1 s/^ *[0-9][0-9]*[* ] //' - ) + if [[ "$HISTCONTROL" == *ignore+(both|space)* ]] + then + this_command="${BASH_COMMAND:-}" + else + this_command=$( LC_ALL=C HISTTIMEFORMAT= builtin history 1 | sed '1 s/^ *[0-9][0-9]*[* ] //' ) + fi # Sanity check to make sure we have something to invoke our function with. if [[ -z "$this_command" ]]; then