Look up word definitions with WordNet and a shell script

Sometimes, a stupidly simple tool that took two minutes to make can prove to be a rather useful timesaver. My latest short shell script is a case in point. As a technical writer, I have to make sure that the words I use don't introduce ambiguity. This means that every now and then I need to look up a word to check its precise meaning. Usually I'd use the available online references for that, but I wanted to make the process more efficient.

Most mainstream Linux distributions have the excellent WordNet lexical database of English in the official software repositories. So I cobbled together a simple shell script that looks up the currently selected word in the database and displays the result in the dialog box. The script uses three packages that can be installed using the sudo zypper in wordnet xclip kdialog command on openSUSE. The actual code is simplicity itself, and it doesn't really require any further explanation:

#!/usr/bin/env bash
s=$(xclip -o)
wn "$s" -over | xclip
t=$(xclip -o)
kdialog --msgbox "$t"

I saved the script in the ~/bin directory under the wn.sh name, made it executable using the chmod +x ~/bin/wn.sh command, and assigned a global keyboard shortcut to it. That was all there was to it. Now I can look up any word without leaving the comfort of the application I'm currently in. Stupidly simple? Yes. Useful? You bet!

© Dmitri Popov