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 21cd891
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions bash-preexec.sh
Original file line number Diff line number Diff line change
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+(dups|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 21cd891

Please sign in to comment.