Skip to content

Commit 21cd891

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 bc8bfe4 commit 21cd891

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

bash-preexec.sh

+6-4
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,12 @@ __bp_preexec_invoke_exec() {
232232
fi
233233

234234
local this_command
235-
this_command=$(
236-
export LC_ALL=C
237-
HISTTIMEFORMAT= builtin history 1 | sed '1 s/^ *[0-9][0-9]*[* ] //'
238-
)
235+
if [[ "$HISTCONTROL" == *ignore+(dups|space)* ]]
236+
then
237+
this_command="${BASH_COMMAND:-}"
238+
else
239+
this_command=$( LC_ALL=C HISTTIMEFORMAT= builtin history 1 | sed '1 s/^ *[0-9][0-9]*[* ] //' )
240+
fi
239241

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

0 commit comments

Comments
 (0)