From 538aff4b2e89ef3eba15dfc6f0d72fe482e5cd71 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Tue, 31 Aug 2021 14:07:04 -0700 Subject: [PATCH] plugin/history: no need to set a trap Instead of globbally clearing `$HISTTIMEFORMAT` and setting a return trap to re-enable it, just make it local to the function. Also, set the defaults in a way that is happy with read-only parameters. # Conflicts: # plugins/available/history.plugin.bash --- plugins/available/history.plugin.bash | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/plugins/available/history.plugin.bash b/plugins/available/history.plugin.bash index 08ca8de634..ac7dea0aee 100644 --- a/plugins/available/history.plugin.bash +++ b/plugins/available/history.plugin.bash @@ -2,26 +2,21 @@ cite about-plugin about-plugin 'improve history handling with sane defaults' -# append to bash_history if Terminal.app quits +# append to bash_history on exit. shopt -s histappend -# erase duplicates; alternative option: export HISTCONTROL=ignoredups -export HISTCONTROL=${HISTCONTROL:-ignorespace:erasedups} +# erase duplicates; alternative option: HISTCONTROL=ignoredups +: "${HISTCONTROL:=ignorespace:erasedups}" # resize history to 100x the default (500) -export HISTSIZE=${HISTSIZE:-50000} +: "${HISTSIZE:=50000}" top-history() { about 'print the name and count of the most commonly run tools' - if [[ -n $HISTTIMEFORMAT ]]; then - # To parse history we need a predictable format, which HISTTIMEFORMAT - # gets in the way of. So we unset it and set a trap to guarantee the - # user's environment returns to normal even if the pipeline below fails. - # shellcheck disable=SC2064 - trap "export HISTTIMEFORMAT='$HISTTIMEFORMAT'" RETURN - unset HISTTIMEFORMAT - fi + # To parse history we need a predictable format, which HISTTIMEFORMAT + # gets in the way of. So we clear it locally. + local HISTTIMEFORMAT history \ | awk '{