Mac版本,因为unix 和 linux的sed命令有差异,注意换行符号的处理:<div><div># Mac Version</div><div># notic: ^M^L = Ctrl+v Ctrl+Enter Ctrl+v Ctrl+l</div><div>ts(){ </div><div>result=`curl -s \</div>
<div> "<a href="http://dict.cn/ws.php?utf8=true&q=$1">http://dict.cn/ws.php?utf8=true&q=$1</a>" `;</div><div><br></div><div>echo $result | sed -E -n 's/.*<def>([^<]+)<\/def>.*/\1/p'; </div>
<div><br></div><div>#examples</div><div>echo $result \</div><div> | sed -E -n 's/.*def> (<sent><orig>.*<\/sent>).*/\1/p' \</div><div> | sed 's/<em>//g' \</div><div>
| sed 's/<\/em>//g' \</div><div> | sed 's/<trans>/^M^L/g' \</div><div> | sed 's/<orig>/^M^L/g' \</div><div> | sed 's/<[^<>]*>//g' ;</div><div>
<br></div><div>return 0;</div><div><br></div><div>}</div><br><div class="gmail_quote">在 2012年5月12日 下午4:16,Hex Lee <span dir="ltr"><<a href="mailto:lihe757@gmail.com" target="_blank">lihe757@gmail.com</a>></span>写道:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>大家好:</div><div><img src="cid:ii_13740164f74c99dc" alt="内嵌图片 1"></div><div>我根据chrome 插件halo word dictionary 写了一个新版本的bash脚本与大家分享,另外感谢他们提供的翻译服务</div>
<div>功能:</div><div>纯粹的字典功能,一次只能查一个单词</div><div>特色:</div><div>更详细,带词性,带例句</div>
<div><br></div><div>效果如下:</div><div><div>$ ts apple</div><div>n.苹果, 珍宝, 家伙 </div><div><br></div><div>My uncle has an apple orchard.</div><div>我叔叔拥有一个苹果园。 </div><div>The apple pie and custard are delicious.</div><div>苹果饼和软冻的味道好极了。 </div>
<div>The apple trees are blossoming.</div><div>苹果树正在开花。</div><div><br></div><div>$ ts driver</div><div>n.驾驶员, 司机, 驱动器 </div><div><br></div><div>The driver was not to blame for the accident.</div><div>这次事故怪不着司机。 </div><div>
I'm a hopeless driver, but the examiner let me through.</div><div>我开车的技术糟透了,但考官让我及格了。 </div><div>The driver was weaving his way through the traffic.</div><div>司机在车辆和人流中曲折前进。</div></div><div><br></div><div>bash脚本,使用方法和以前一样加入到~/.bashrc(for linux) :</div>
<div><br></div><div><div>ts(){</div><div>result=`curl -s \</div><div> "<a href="http://dict.cn/ws.php?utf8=true&q=$1" target="_blank">http://dict.cn/ws.php?utf8=true&q=$1</a>" `;</div><div><br></div>
<div>echo $result | sed -r -n 's/.*<def>([^<]+)<\/def>.*/\1/p'; </div>
<div><br></div><div>#examples</div><div>echo $result \</div><div> | sed -r -n 's/.*def> (<sent><orig>.*<\/sent>).*/\1/p' \</div><div> | sed 's/<em>//g' \</div><div>
| sed 's/<\/em>//g' \</div><div> | sed 's/<trans>/\n/g' \</div><div> | sed 's/<orig>/\n/g' \</div><div> | sed 's/<[^<>]*>//g';</div><div>
<br>
</div><div>return 0;</div><div><br></div><div>}</div></div><div class="HOEnZb"><div class="h5"><div><br><br><div class="gmail_quote">2012/4/13 codewalkertse <span dir="ltr"><<a href="mailto:xyy.xx.victor@gmail.com" target="_blank">xyy.xx.victor@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">非常好的一个脚本 感谢分享<div><div><br><br>在 2012年3月23日星期五UTC+8下午11时26分10秒,Hex Lee写道:<blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>ts(){</div><div><br></div><div>curl -s \</div><div> "<a href="http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=dict.top" target="_blank">http://fanyi.youdao.com/<u></u>translate?smartresult=dict&<u></u>smartresult=rule&smartresult=<u></u>ugc&sessionFrom=dict.top</a>" \</div>
<div> -d \</div><div><span style="white-space:pre-wrap"> </span>"type=AUTO& i=$1&doctype=json&xmlVersion=<u></u>1.4&keyfrom=fanyi.web&ue=UTF-<u></u>8&typoResult=true&flag=false" \</div>
<div> | sed -E -n 's/.*tgt":"([^"]+)".*/\1/p' ;</div><div><br></div><div>return 0;</div><div>}</div><div><br></div><div><div>设置如下:</div><div>linux用户:</div><div>1.添加此脚本到~/.bashrc的末尾</div>
<div>2.source ~/.bashrc</div><div>Mac osX用户:</div><div> </div><div>1.添加此脚本到~/.bash_profile的末尾,<u></u>没有就新建</div><div>2.source ~/.bash_profile</div><div> </div><div>使用:</div><div> </div><div> </div><div>Shell代码 </div><div>
$ ts hello </div>
<div>你好 </div><div>$ ts "how are you?" </div><div>你好吗? </div><div> </div><div>也可以翻译中文。</div><div> </div></div><div><a href="http://hexlee.iteye.com/blog/1442506" target="_blank">原文地址</a><br></div>
</blockquote><br>在 2012年3月23日星期五UTC+8下午11时26分10秒,Hex Lee写道:<blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div>ts(){</div><div><br></div><div>curl -s \</div>
<div> "<a href="http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=dict.top" target="_blank">http://fanyi.youdao.com/<u></u>translate?smartresult=dict&<u></u>smartresult=rule&smartresult=<u></u>ugc&sessionFrom=dict.top</a>" \</div>
<div> -d \</div><div><span style="white-space:pre-wrap"> </span>"type=AUTO& i=$1&doctype=json&xmlVersion=<u></u>1.4&keyfrom=fanyi.web&ue=UTF-<u></u>8&typoResult=true&flag=false" \</div>
<div> | sed -E -n 's/.*tgt":"([^"]+)".*/\1/p' ;</div><div><br></div><div>return 0;</div><div>}</div><div><br></div><div><div>设置如下:</div><div>linux用户:</div><div>1.添加此脚本到~/.bashrc的末尾</div>
<div>2.source ~/.bashrc</div><div>Mac osX用户:</div><div> </div><div>1.添加此脚本到~/.bash_profile的末尾,<u></u>没有就新建</div><div>2.source ~/.bash_profile</div><div> </div><div>使用:</div><div> </div><div> </div><div>Shell代码 </div><div>
$ ts hello </div>
<div>你好 </div><div>$ ts "how are you?" </div><div>你好吗? </div><div> </div><div>也可以翻译中文。</div><div> </div></div><div><a href="http://hexlee.iteye.com/blog/1442506" target="_blank">原文地址</a><br></div>
</blockquote><br>在 2012年3月23日星期五UTC+8下午11时26分10秒,Hex Lee写道:<blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div>ts(){</div><div><br></div><div>curl -s \</div>
<div> "<a href="http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=dict.top" target="_blank">http://fanyi.youdao.com/<u></u>translate?smartresult=dict&<u></u>smartresult=rule&smartresult=<u></u>ugc&sessionFrom=dict.top</a>" \</div>
<div> -d \</div><div><span style="white-space:pre-wrap"> </span>"type=AUTO& i=$1&doctype=json&xmlVersion=<u></u>1.4&keyfrom=fanyi.web&ue=UTF-<u></u>8&typoResult=true&flag=false" \</div>
<div> | sed -E -n 's/.*tgt":"([^"]+)".*/\1/p' ;</div><div><br></div><div>return 0;</div><div>}</div><div><br></div><div><div>设置如下:</div><div>linux用户:</div><div>1.添加此脚本到~/.bashrc的末尾</div>
<div>2.source ~/.bashrc</div><div>Mac osX用户:</div><div> </div><div>1.添加此脚本到~/.bash_profile的末尾,<u></u>没有就新建</div><div>2.source ~/.bash_profile</div><div> </div><div>使用:</div><div> </div><div> </div><div>Shell代码 </div><div>
$ ts hello </div>
<div>你好 </div><div>$ ts "how are you?" </div><div>你好吗? </div><div> </div><div>也可以翻译中文。</div><div> </div></div><div><a href="http://hexlee.iteye.com/blog/1442506" target="_blank">原文地址</a><br></div>
</blockquote><br>在 2012年3月23日星期五UTC+8下午11时26分10秒,Hex Lee写道:<blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div>ts(){</div><div><br></div><div>curl -s \</div>
<div> "<a href="http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=dict.top" target="_blank">http://fanyi.youdao.com/<u></u>translate?smartresult=dict&<u></u>smartresult=rule&smartresult=<u></u>ugc&sessionFrom=dict.top</a>" \</div>
<div> -d \</div><div><span style="white-space:pre-wrap"> </span>"type=AUTO& i=$1&doctype=json&xmlVersion=<u></u>1.4&keyfrom=fanyi.web&ue=UTF-<u></u>8&typoResult=true&flag=false" \</div>
<div> | sed -E -n 's/.*tgt":"([^"]+)".*/\1/p' ;</div><div><br></div><div>return 0;</div><div>}</div><div><br></div><div><div>设置如下:</div><div>linux用户:</div><div>1.添加此脚本到~/.bashrc的末尾</div>
<div>2.source ~/.bashrc</div><div>Mac osX用户:</div><div> </div><div>1.添加此脚本到~/.bash_profile的末尾,<u></u>没有就新建</div><div>2.source ~/.bash_profile</div><div> </div><div>使用:</div><div> </div><div> </div><div>Shell代码 </div><div>
$ ts hello </div>
<div>你好 </div><div>$ ts "how are you?" </div><div>你好吗? </div><div> </div><div>也可以翻译中文。</div><div> </div></div><div><a href="http://hexlee.iteye.com/blog/1442506" target="_blank">原文地址</a><br></div>
</blockquote><br>在 2012年3月23日星期五UTC+8下午11时26分10秒,Hex Lee写道:<blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div>ts(){</div><div><br></div><div>curl -s \</div>
<div> "<a href="http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=dict.top" target="_blank">http://fanyi.youdao.com/<u></u>translate?smartresult=dict&<u></u>smartresult=rule&smartresult=<u></u>ugc&sessionFrom=dict.top</a>" \</div>
<div> -d \</div><div><span style="white-space:pre-wrap"> </span>"type=AUTO& i=$1&doctype=json&xmlVersion=<u></u>1.4&keyfrom=fanyi.web&ue=UTF-<u></u>8&typoResult=true&flag=false" \</div>
<div> | sed -E -n 's/.*tgt":"([^"]+)".*/\1/p' ;</div><div><br></div><div>return 0;</div><div>}</div><div><br></div><div><div>设置如下:</div><div>linux用户:</div><div>1.添加此脚本到~/.bashrc的末尾</div>
<div>2.source ~/.bashrc</div><div>Mac osX用户:</div><div> </div><div>1.添加此脚本到~/.bash_profile的末尾,<u></u>没有就新建</div><div>2.source ~/.bash_profile</div><div> </div><div>使用:</div><div> </div><div> </div><div>Shell代码 </div><div>
$ ts hello </div>
<div>你好 </div><div>$ ts "how are you?" </div><div>你好吗? </div><div> </div><div>也可以翻译中文。</div><div> </div></div><div><a href="http://hexlee.iteye.com/blog/1442506" target="_blank">原文地址</a><br></div>
</blockquote></div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>