Advertisement
Guest User

Dictionary lookup (full featured)

a guest
Aug 7th, 2010
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.99 KB | None | 0 0
  1. define() {
  2.     local ret
  3.     local lines=0
  4.     local match
  5.     local url="dict://dict.org"
  6.     if [ $# -eq 0 ]; then
  7.         echo "Usage: 'define word'"
  8.         echo "Use specific database: 'define word db'"
  9.         echo "Get listing of possible databases: 'define showdb'"
  10.         echo "Word match: 'define word-part match-type' (suf, pre, sub, re)"
  11.         echo "Suffix, prefix, substring, regular expression respectively"
  12.         echo "If you use regular expression matching: 'define ^s.*r re'"
  13.     fi
  14.     if [ $# -eq 1 ]; then
  15.         if [ $1 == "showdb" ]; then
  16.             ret="`curl -# ${url}/show:db|tail -n +3|head -n -2|sed 's/^110.//'`"
  17.         else
  18.             #Lookup word
  19.             ret="`curl -# ${url}/d:$1|tail -n +3|head -n -2|sed 's/^15[0-2].//'`"
  20.         fi
  21.     fi  
  22.     if [ $# -eq 2 ]; then
  23.         case "$2" in
  24.         "suf")
  25.             #Match by suffix
  26.             match="suffix"
  27.             ret="`curl -# ${url}/m:$1::${match}|tail -n +3|head -n -2|sed 's/^15[0-2].//'`"
  28.         ;;  
  29.         "pre")
  30.             #Match by prefix
  31.             match="prefix";
  32.             ret="`curl -# ${url}/m:$1::${match}|tail -n +3|head -n -2|sed 's/^15[0-2].//'`"
  33.         ;;  
  34.         "sub")
  35.             #Match by substring
  36.             match="substring";
  37.             ret="`curl -# ${url}/m:$1::${match}|tail -n +3|head -n -2|sed 's/^15[0-2].//'`"
  38.         ;;  
  39.         "re")
  40.             #Regular expression match
  41.             match="re";
  42.             ret="`curl -# ${url}/m:$1::${match}|tail -n +3|head -n -2|sed 's/^15[0-2].//'`"
  43.         ;;  
  44.         *)
  45.             #Use specific databse for lookup
  46.             ret="`curl -# ${url}/d:$1:$2|tail -n +3|head -n -2|sed 's/^15[0-2].//'`"
  47.         ;;  
  48.         esac
  49.     fi  
  50.    
  51.     lines=`echo "${ret}"|grep -c -`
  52.    
  53.     #Output
  54.     if [ ${lines} -gt 4 ]; then
  55.         #Use less if more than 4 definitions
  56.         echo "${ret}"|less -R
  57.     else
  58.         echo "${ret}"
  59.     fi  
  60. }  
  61.  
  62. thesaurus() {
  63.     define $1 moby-thes
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement