From d9c0892b5a1834de27fbb7a92fcf1cdfcdd04286 Mon Sep 17 00:00:00 2001 From: oxnz Date: Wed, 8 Jan 2014 18:10:57 +0800 Subject: [PATCH 1/2] add google function --- plugins/osx/osx.plugin.zsh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh index 608ec3789..fca3407e5 100644 --- a/plugins/osx/osx.plugin.zsh +++ b/plugins/osx/osx.plugin.zsh @@ -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 +} From d3c84b142e4bf62fdb127feb7c1f3e5be4acad17 Mon Sep 17 00:00:00 2001 From: oxnz Date: Wed, 8 Jan 2014 18:17:51 +0800 Subject: [PATCH 2/2] add histop function to show most used commands from history --- plugins/history/history.plugin.zsh | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/plugins/history/history.plugin.zsh b/plugins/history/history.plugin.zsh index 0f4aa4b10..cae053599 100644 --- a/plugins/history/history.plugin.zsh +++ b/plugins/history/history.plugin.zsh @@ -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 " + 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 +}