This commit is contained in:
0xnz 2014-07-01 04:05:32 +00:00
commit 351553ab03
2 changed files with 53 additions and 0 deletions

View file

@ -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
}

View file

@ -191,3 +191,22 @@ function itunes() {
osascript -e "tell application \"iTunes\" to $opt"
}
# enable google search from terminal
function google() {
local url="https://www.google.com/search?hl=en#newwindow=1&q="
case "$1" in
"" | -h | --help)
cat << EOH
google:
google "keyword" to search
EOH
exit 0
;;
*)
while [ $# -ge 1 ]; do
open "$url"$(echo ${1// /+} | xxd -plain | sed 's/\(..\)/%\1/g')
shift
done
;;
esac
}