1,查单词(废话)
2,相关例句
3,建立缓存文件
4,读单词
5,进行模糊匹配
- #!/bin/bash
- # This is a dictionary based for Termial.
- # Its cache directory is in ~/.ydictionary/
- PS3='Your choice is : '
- word="$*"
- cache=~/.ydictionary/"$word"
- # read this word
- read_word()
- {
- re_word="$1"
- mplayer "" >/dev/null 2>&1
- if [ $? ]
- then
- :
- else
- espeak -s 130 "$re_word" 1>/dev/null 2>&1
- fi
- exit 0
- }
- # judge whether read this word.
- judge_read()
- {
- readword="$1"
- clew="Read it?(y/n)y:"
- echo -ne "\033[35;1m$clew\033[00m"
- read answer
- : ${answer:=y}
- if [ "$answer" = "y" ];then
- read_word "$readword"
- else
- exit 5
- fi
- }
- if [ $# -lt 1 ];then
- echo
- echo "usag: `basename $0` [word]"
- echo
- exit 1
- fi
- if [ -e "$cache" ];then
- word2=$(cat "$cache")
- echo -e "\033[34;1m$word2\033[0m"
- echo
- judge_read "$word"
- exit 0
- elif [ ! -e ${cache%/*} ];then
- mkdir -p ${cache%/*}
- fi
-
- # 抓取网页快照。
- wordf=$(wget -q "" -O -)
-
- # 截取指定字符段。
- # 判断是否有单词匹配,如果没有给出相近的。否则就进行查询。
- if echo "$wordf"|grep 'sugg' 1>/dev/null 2>&1
- then
- echo "You may want to search these words."
- sword=$(echo "$wordf"|sed -e 's/<[\/]*sugg>//g'|grep '^[^<]'|tr ["\n"] ["\t"])
- select guessw in $sword ;do
- if [ $guessw ];then
- echo -e "\033[36;1m$guessw\033[0m"
- ydic $guessw
- exit 2
- else
- read -n 1 -p "Do you want to try again:(y/n)y:" choice
- : ${choice:=y}
- echo
- if [ "$choice" = "y" ] || [ "$choice" = "Y" ];then
- echo 'Please input again:'
- else
- exit 3
- fi
- fi
- done
- else
- word1=$(echo "$wordf"|sed -e 's/<[\/]*\(def\|sent\|orig\|trans\)>//g' -e 's/<em>\(.*\)<\/em>/( \1 )/g' -e 's/\(>\|<\)/ /g'|grep '^[^<]')
- echo "$word1">"$cache"
- echo -e "\033[32;1m$word1\033[0m"
- echo
- judge_read "$word"
- judge=$(cat "$cache")
- if [ "$judge" == "Not Found" ];then
- rm -f "$cache"
- fi
- #cache如果大于一百兆,提示用户。进行释放。
- total=$(du ${cache%/*}|cut -d/ -f 1)
- if [ $total -gt 102400 ];then
- echo
- echo -e "\tThe dictionary cache is beyond 100M.Maybe you can release some space."
- fi
- fi
- exit 0