#!/bin/sh # Look up selected word in dictionary (wn) and display info in xmessage popup. # ('selected word' is primary X selection) # Requires 'xclip', 'sselp' or similar program. # alt program. dict. eg. # sh -c 'dict `xclip -o`; cat' # just print out to stdout if being run in a terminal [ -t 1 ] && export terminal=true Usage=" Usage: wnx -[d|a|s] WORD\n if WORD is missing, try primary X selection \n plus 1 of the below:\n -d definition\n -t thesaurus\n -a antonymns\n -s synonymns\n -w WORD (alt way to pass WORD)\n -h help" usage () { if [ -n "$terminal" ]; then printf "$Usage\n" else printf $Usage | xmessage -center -title "WordNet Error" -file - fi exit 1 } # process args while getopts dtashw: arg do case $arg in d) action="-over"; title="Dictionary"; shift;; a) action="-antsn -antsv -antsa -antsr"; title="Antonymns"; shift;; s) action="-synsn -synsv -synsa -synsr "; title="Synonymns"; shift;; t) action="-synsn -synsv -synsa -synsr -antsn -antsv -antsa -antsr"; \ title="Thesaurus"; shift;; w) word="$OPTARG"; shift;; h) usage;; esac done [ -n "$1" ] && word="$1" #echo $word # the word is required if [ -z "$word" ]; then #word=`xclip -o -selection primary` word=`sselp` fi if [ -z "$action" ]; then action="-over"; title="Dictionary"; fi #echo word $word #echo #echo "wn $word $action"; #echo msg=`wn "$word" $action` if [ -n "$msg" ]; then if [ -n "$terminal" ]; then printf "$msg\n" | fold -w 78 else printf "$msg" | fold -w 95 | boxes -d ada-box -p a2 | \ xmessage -timeout 30 -title $title -file - & fi fi #if [ -n "$action" -a -n "$word" ]; then # wn "$word" $action | fold -w 95 | boxes -d ada-box -p a2 | \ # xmessage -title $title -file - & #fi # other nice boxes # ada-box # columns # diamonds # peek