Skip to content

Commit

Permalink
add top-history
Browse files Browse the repository at this point in the history
  • Loading branch information
cornfeedhobo committed Jan 15, 2021
1 parent f2d05a9 commit 16d0100
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions plugins/available/history.plugin.bash
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,29 @@ export HISTCONTROL=${HISTCONTROL:-ignorespace:erasedups}

# resize history to 100x the default (500)
export HISTSIZE=${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.
trap "export HISTTIMEFORMAT='$HISTTIMEFORMAT'" RETURN
unset HISTTIMEFORMAT
fi

history \
| awk '{
a[$2]++
}END{
for(i in a)
printf("%s\t%s\n", a[i], i)
}' \
| sort --reverse --numeric-sort \
| head \
| column \
--table \
--table-columns 'Command Count,Command Name' \
--output-separator ' | '
}

0 comments on commit 16d0100

Please sign in to comment.