命令行快捷搜索internet
Posted redguardtoo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了命令行快捷搜索internet相关的知识,希望对你有一定的参考价值。
firefox中有个功能很有用,就是输入g然后后面加上要搜索的关键字,就可以自动到google上搜索。这个功能叫QuickSearch。
我希望在命令行下也有这个功能,所以自己写了名为search的bash script。可以在命令行中直接调用文本界面的浏览器搜索(例如w3m或者lynx).
使用方法如下:
在google中搜索关键字:
$search g keyword [keyword]...
在google blogsearch中搜索关键字:
$search b keyword [keyword]...
查辞典:
$search d keyword
如果你设置好alias(实际上search会帮你做得):
那么上面的的三种搜索可以简化为
$g keyword [keyword]...
$b keyword [keyword]...
$d keyword
搜索引擎是可以定制的,定制的过程及其简单,和firefox的QuickSearch的设置没有区别。
将search安装到/usr/bin目录:
$search install
输出设置alias的脚本到标准输出:
$search mkalias
典型的安装过程:
$su
$search install;exit
$search mkalias >> ~/.bashrc; source ~/.bashrc
以下是源代码:
我希望在命令行下也有这个功能,所以自己写了名为search的bash script。可以在命令行中直接调用文本界面的浏览器搜索(例如w3m或者lynx).
使用方法如下:
在google中搜索关键字:
$search g keyword [keyword]...
在google blogsearch中搜索关键字:
$search b keyword [keyword]...
查辞典:
$search d keyword
如果你设置好alias(实际上search会帮你做得):
那么上面的的三种搜索可以简化为
$g keyword [keyword]...
$b keyword [keyword]...
$d keyword
搜索引擎是可以定制的,定制的过程及其简单,和firefox的QuickSearch的设置没有区别。
将search安装到/usr/bin目录:
$search install
输出设置alias的脚本到标准输出:
$search mkalias
典型的安装过程:
$su
$search install;exit
$search mkalias >> ~/.bashrc; source ~/.bashrc
以下是源代码:
#
!/bin/sh
# 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 "
exit 1
fi
if [ " $1 " == " install " ];then
echo " Installing... "
cp $ 0 / usr / bin / $PROG
exit 0
fi
if [ " $1 " == " uninstall " ];then
echo " Uninstalling... "
rm / usr / bin / $PROG
exit 0
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
# 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 "
exit 1
fi
if [ " $1 " == " install " ];then
echo " Installing... "
cp $ 0 / usr / bin / $PROG
exit 0
fi
if [ " $1 " == " uninstall " ];then
echo " Uninstalling... "
rm / usr / bin / $PROG
exit 0
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
以上是关于命令行快捷搜索internet的主要内容,如果未能解决你的问题,请参考以下文章