Skip to content

Commit 16d0100

Browse files
committed
add top-history
1 parent f2d05a9 commit 16d0100

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

plugins/available/history.plugin.bash

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,29 @@ export HISTCONTROL=${HISTCONTROL:-ignorespace:erasedups}
99

1010
# resize history to 100x the default (500)
1111
export HISTSIZE=${HISTSIZE:-50000}
12+
13+
top-history() {
14+
about 'print the name and count of the most commonly run tools'
15+
16+
if [[ -n $HISTTIMEFORMAT ]]; then
17+
# To parse history we need a predictable format, which HISTTIMEFORMAT
18+
# gets in the way of. So we unset it and set a trap to guarantee the
19+
# user's environment returns to normal even if the pipeline below fails.
20+
trap "export HISTTIMEFORMAT='$HISTTIMEFORMAT'" RETURN
21+
unset HISTTIMEFORMAT
22+
fi
23+
24+
history \
25+
| awk '{
26+
a[$2]++
27+
}END{
28+
for(i in a)
29+
printf("%s\t%s\n", a[i], i)
30+
}' \
31+
| sort --reverse --numeric-sort \
32+
| head \
33+
| column \
34+
--table \
35+
--table-columns 'Command Count,Command Name' \
36+
--output-separator ' | '
37+
}

0 commit comments

Comments
 (0)