Skip to content

Commit 3e0e9b5

Browse files
committed
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`.
1 parent 10b41c5 commit 3e0e9b5

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

bash-preexec.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,12 @@ __bp_preexec_invoke_exec() {
225225
fi
226226

227227
local this_command
228-
this_command=$(
229-
export LC_ALL=C
230-
HISTTIMEFORMAT= builtin history 1 | sed '1 s/^ *[0-9][0-9]*[* ] //'
231-
)
228+
if [[ "$HISTCONTROL" == *ignore+(dups|space)* ]]
229+
then
230+
this_command="${BASH_COMMAND:-}"
231+
else
232+
this_command=$( LC_ALL=C HISTTIMEFORMAT= builtin history 1 | sed '1 s/^ *[0-9][0-9]*[* ] //' )
233+
fi
232234

233235
# Sanity check to make sure we have something to invoke our function with.
234236
if [[ -z "$this_command" ]]; then

0 commit comments

Comments
 (0)