Skip to content

Commit

Permalink
Use $BASH_COMMAND if HISTCONTROL is incompatible
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
gaelicWizard committed Jul 28, 2021
1 parent bc8bfe4 commit 321d74e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions bash-preexec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 321d74e

Please sign in to comment.