Skip to content

Commit e70ab94

Browse files
committed
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
1 parent 760d762 commit e70ab94

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

plugins/available/history.plugin.bash

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,26 @@ about-plugin 'improve history handling with sane defaults'
55
# variable when the shell exits, rather than overwriting the file.
66
shopt -s histappend
77

8-
# erase duplicates; alternative option: export HISTCONTROL=ignoredups
9-
export HISTCONTROL=${HISTCONTROL:-ignorespace:erasedups}
8+
# erase duplicates; alternative option: HISTCONTROL=ignoredups
9+
: "${HISTCONTROL:=ignorespace:erasedups}"
1010

1111
# resize history to 100x the default (500)
12-
export HISTSIZE=${HISTSIZE:-50000}
12+
: "${HISTSIZE:=50000}"
1313

1414
# Flush history to disk after each command.
1515
export PROMPT_COMMAND="history -a;${PROMPT_COMMAND}"
1616

1717
function top-history() {
1818
about 'print the name and count of the most commonly run tools'
19+
# To parse history we need a predictable format, which HISTTIMEFORMAT
20+
# gets in the way of. So we clear it locally.
21+
local HISTTIMEFORMAT
1922

2023
# - Make sure formatting doesn't interfer with our parsing
2124
# - Use awk to count how many times the first command on each line has been called
2225
# - Truncate to 10 lines
2326
# - Print in column format
24-
HISTTIMEFORMAT='' history \
27+
history \
2528
| awk '{
2629
a[$2]++
2730
}END{

0 commit comments

Comments
 (0)