# Written by redguardtoo <http://blog.csdn.net/redguardtoo> SEARCH_ALIAS=(g r n wi c b d) SEARCH_URL=("http://www.google.com/search?q=%s&ie=utf-8&oe=utf-8" "http://groups.google.com/groups?q=%s&sourceid=opera&num=%i&ie=utf-8&oe=utf-8" "http://news.google.com/news?q=%s&sourceid=opera&num=%i&ie=utf-8&oe=utf-8" "https://secure.wikimedia.org/wikipedia/en/wiki/Special:Search?search=%s" "https://secure.wikimedia.org/wikipedia/zh/wiki/Special:Search?search=%s" "http://blogsearch.google.com/blogsearch?hl=en&ie=UTF-8&q=%s&btnG=Search+Blogs" "http://www.m-w.com/dictionary/%s" ) BROWSER_PROG=w3m BROWSER_OPTION="-O GBK -cookie" PROG=`basename $0`
#if [ $(whoami) != 'root' ]; then #echo "Must be root to run $0" #exit 1; #fi if [ -z $1 ]; then echo "search version 0.0.1" echo "usage: $PROG alias keyword" echo " $PROG install" echo " $PROG uninstall" echo " $PROG mkalias" exit1 fi
if [ "$1"=="install" ];then echo "Installing..." cp $0/usr/bin/$PROG exit0 fi
if [ "$1"=="uninstall" ];then echo "Uninstalling..." rm /usr/bin/$PROG exit0 fi
if [ "$1"=="mkalias" ];then for sa in ${SEARCH_ALIAS[@]};do echo alias $sa="/usr/bin/$PROG $sa" done exit 0 fi
QUERY_SHORTCUT=$1 #echo $# #debug if [ $# -gt 1 ];then shift QUERY_PARA=$* #echo $QUERY_PARA #debug fi
count=0 for sa in ${SEARCH_ALIAS[@]};do if [ "$QUERY_SHORTCUT" == "$sa" ];then QUERY_URL=${SEARCH_URL[$count]} QUERY_URL=${QUERY_URL//"%s"/"$QUERY_PARA"} QUERY_URL=${QUERY_URL//""/"+"} #echo $QUERY_URL #debug $BROWSER_PROG $BROWSER_OPTION ${QUERY_URL/"%s"/"$QUERY_PARA"} fi count=$(($count + 1)) done