mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-13 03:01:32 +01:00
add histop function to show most used commands from history
This commit is contained in:
parent
d9c0892b5a
commit
d3c84b142e
1 changed files with 34 additions and 0 deletions
|
|
@ -6,3 +6,37 @@ function hs
|
|||
}
|
||||
|
||||
alias hsi='hs -i'
|
||||
|
||||
# show the most used commands from history
|
||||
function histop() {
|
||||
local FNAME='histop'
|
||||
local n=10
|
||||
if [[ $# -ne 0 ]]; then
|
||||
case $1 in
|
||||
-h|--help)
|
||||
echo "Usage: $FNAME -n <num>"
|
||||
echo "num: print num lines of most used command"
|
||||
return 0
|
||||
;;
|
||||
-n)
|
||||
if [ $# -eq 2 -a $2 -ge 1 -a $2 -le $HISTSIZE ]; then
|
||||
n=$2
|
||||
shift
|
||||
else
|
||||
echo "option -n needs an number"
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "$FNAME: Unknown option: $1"
|
||||
$FNAME --help
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
fi
|
||||
print "Number\tTimes\tFrequency\tCommand"
|
||||
history 1 | awk -v n=$n '{ cmds[$2]++; } END { i = 1; for (cmd in cmds) {
|
||||
if (i++ <= n) printf("%-8d%8.2f%%\t%-16s\n", cmds[cmd],
|
||||
(100*cmds[cmd])/NR, cmd); else break; }}' | sort -nr | nl
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue