感觉还是很好用,不用再开启星际或词霸了,速度快好多。
注:这里分成两个脚本,一个循环查询的,适合大家在读英文的时候时不时查下单词用,叫idic。
另一个是只查询一次就退出的,适合临时查下单词,叫dic。
大家如果有什么不爽的地方,既可以自己改,也可以在issue里面直接留言。
希望大家能喜欢,这个东西也能帮助大家。
这个是项目地址:http://code.google.com/p/dictionary4linux/
由于google code有时候会被重set,所以下面我就直接贴出代码:
利用notify-send输出结果
代码: 全选
#!/bin/bash
ARGS=1
E_BADARGS=65
#prepare the cache dir to save the translate offline
if [ ! -e ~/dictionary ];
then
echo "make dir...."
mkdir ~/dictionary
fi
#check the arg that user inputed
if [ $# -ne "$ARGS" ];
then
echo "Usage:`basename $0` word"
exit $E_BADARGS
fi
if [ ! -f ~/dictionary/$1 ];
then
#read the translate from dict of baidu.com
#PS: Why to use Baidu? The answer is simple, fast.
w3m -no-cookie -dump 'http://dict.baidu.com/s?wd='$1'&f=3' \
| sed '/以下结果来自互联网网络释义/,$d'| sed '1,15d' | tac \
| sed '1,2d' | tac |sed -r '/^[0-9]+\./N;s/\n//' > ~/dictionary/$1
fi
msg=`cat ~/dictionary/$1`
if [ "$msg" = "" ];
then
msg="您所查询的$1无法找到解释。"
fi
notify-send "$1" "$msg" >/dev/null 2>&1
if [ $? -eq 0 ];
then
exit 0
else
echo
echo -e "--------------------\033[1;40;33m $1 \033[0m--------------------"
echo "$msg"
exit 0
fi
直接在终端输出结果
代码: 全选
#!/bin/bash
ARGS=1
E_BADARGS=65
#prepare the cache dir to save the translate offline
if [ ! -e ~/dictionary ];
then
echo "make dir...."
mkdir ~/dictionary
fi
#check the arg that user inputed
if [ $# -ne "$ARGS" ];
then
echo "Usage:`basename $0` word"
exit $E_BADARGS
fi
if [ ! -f ~/dictionary/$1 ];
then
#read the translate from dict of baidu.com
#PS: Why to use Baidu? The answer is simple, fast.
w3m -no-cookie -dump 'http://dict.baidu.com/s?wd='$1'&f=3' \
| sed '/以下结果来自互联网网络释义/,$d'| sed '1,15d' | tac \
| sed '1,2d' | tac |sed -r '/^[0-9]+\./N;s/\n//' > ~/dictionary/$1
fi
msg=`cat ~/dictionary/$1`
if [ "$msg" = "" ];
then
msg="您所查询的$1无法找到解释。"
fi
echo
echo -e "--------------------\033[1;40;33m $1 \033[0m--------------------"
echo "$msg"
exit 0
循环查询单词
代码: 全选
#!/bin/sh
if [ ! -e ~/dictionary ];
then
mkdir ~/dictionary
fi
clear
echo -e "\033[1;32;33mWelcome to use online dictionary!\033[0m"
while [ 1 = 1 ]
do
echo -en "\033[0;32;33mPlease enter the word(q:quit):\033[0m"
read word
if [ "$word" = "q" ]
then
echo "Bye"
exit 0
fi
if [ -z "$word" ]
then
continue
fi
if [ ! -f ~/dictionary/$word ];
then
w3m -no-cookie -dump 'http://dict.baidu.com/s?wd='$word'&f=3' \
| sed '/以下结果来自互联网网络释义/,$d'| sed '1,15d' | tac \
| sed '1,2d' | tac |sed -r '/^[0-9]+\./N;s/\n//' > ~/dictionary/$word
fi
clear
echo
echo -e "--------------------\033[1;40;33m $word \033[0m--------------------"
cat ~/dictionary/$word
done
exit 0
代码: 全选
sudo cp dic /usr/bin/