From 95a6b7f794ccbc5db0d3a6d758ea89d55ef1c860 Mon Sep 17 00:00:00 2001 From: Evgeny Vereshchagin Date: Tue, 23 Jun 2015 19:41:18 +0000 Subject: [PATCH] Add HISTTIMEFORMAT support See https://github.com/rcaloras/bash-preexec/issues/6#issuecomment-114007154 --- bash-preexec.sh | 2 +- test/bash-preexec.bats | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bash-preexec.sh b/bash-preexec.sh index 3297118..1c70d25 100644 --- a/bash-preexec.sh +++ b/bash-preexec.sh @@ -160,7 +160,7 @@ __bp_preexec_invoke_exec() { return fi - local this_command="$(history 1 | sed -e "s/^[ ]*[0-9]*[ ]*//g")"; + local this_command="$(HISTTIMEFORMAT= history 1 | sed -e "s/^[ ]*[0-9]*[ ]*//g")"; # Sanity check to make sure we have something to invoke our function with. if [[ -z "$this_command" ]]; then diff --git a/test/bash-preexec.bats b/test/bash-preexec.bats index a08b690..289870c 100644 --- a/test/bash-preexec.bats +++ b/test/bash-preexec.bats @@ -133,3 +133,15 @@ test_preexec_echo() { [[ "$HISTCONTROL" == "ignoredups:::some_thing_else" ]] } + +@test "preexec should respect HISTTIMEFORMAT" { + preexec_functions+=(test_preexec_echo) + __bp_preexec_interactive_mode="on" + git_command="git commit -a -m 'commiting some stuff'" + HISTTIMEFORMAT='%F %T ' + history -s $git_command + + run '__bp_preexec_invoke_exec' + [[ $status == 0 ]] + [[ "$output" == "$git_command" ]] +}