• Tip Jar

Command Line Word Tools

It is sometimes nice to have the ability to spellcheck, or find a definition for something right on the command line. There are several tools that can help you accomplish this. For spellchecking, I use a program called hunspell.

pacaur -S hunspell hunspell-en-us-large

hunspell-en-us-large comes from the aur, so if you don’t use pacaur or some other UR helper, you wil need to download and install it.
To use it, simply enter something like the following:

echo "neibor" | hunspell -d en_US-large
error: unknown encoding UTF8: using iso88591 as fallback
error: unknown encoding UTF8: using iso88591 as fallback
error: unknown encoding UTF8: using iso88591 as fallback
error: unknown encoding UTF8: using iso88591 as fallback
Hunspell 1.3.3
& neibor 1 0: neighbor

Here we see that neighbor is mispelled, but the output is a bit ugly. Plus, who want’s to type echo “blah” and pipe it through hunspell every time. Fortunately, you can write a small script, I call it spellcheck, that cuts all the extra typing out as well as cleaning up the output. Let’s see the output from the script:

spellcheck neibor
Hunspell 1.3.3
& neibor 1 0: neighbor

Much better. So, to create this script, simply add the following to ~/bin/spellcheck if you have added that to your path, or /usr/bin/spellcheck if you prefer to have it system wide.

#!/bin/bash
echo "$@" | hunspell -d en_US-large 2> /dev/null
exit 0

Save the file and remember to make it executable with chmod 755 /path/to/spellcheck
Now, you can spellcheck without seriously interupting your workflow. But, what if you come across a word and you don’t know its meaning? Never fear. There’s no need to go firing up a browser and wating for some dictionary site to load so you can wade through pages of ads just to get a one-line definition. There are two command line dictionaries I like to use. First, there is dictd:

pacman -S dictd

To use, type dict and the word you want:

dict skullduggery
1 definition found

From WordNet (r) 3.0 (2006) [wn]:

skullduggery
n 1: verbal misrepresentation intended to take advantage of you
in some way [syn: {trickery}, {hocus-pocus}, {slickness},
{hanky panky}, {jiggery-pokery}, {skulduggery},
{skullduggery}]

You may notice the result comes from something called wordnet. Which is the other dictionary program I tend to use from the CLI. It is in the UR:

pacaur -S wordnet

Usage can vary. On some distros like ubuntu, you type out the word wordnet and the word you want, whereas in arch, you type wn and the word you want. Here’s an example of usage:

wn storm -over

Overview of noun storm

The noun storm has 3 senses (first 2 from tagged texts)

1. (8) storm, violent storm -- (a violent weather condition with winds 64-72 knots (11 on the Beaufort scale) and precipitation and thunder and lightning)
2. (3) storm, tempest -- (a violent commotion or disturbance; "the storms that had characterized their relationship had died away"; "it was only a tempest in a teapot")
3. storm -- (a direct and violent assault on a stronghold)

Overview of verb storm

The verb storm has 5 senses (first 2 from tagged texts)

1. (2) ramp, rage, storm -- (behave violently, as if in state of a great anger)
2. (1) storm, force -- (take by force; "Storm the fort")
3. storm -- (rain, hail, or snow hard and be very windy, often with thunder or lightning; "If it storms, we'll need shelter")
4. storm -- (blow hard; "It was storming all night")
5. storm, surprise -- (attack by storm; attack suddenly)

Finally, you may need to solve an anagram. Or perhapse you’re one of those people who likes playing around with words. Either way, wordplay is for you. Just install it from the UR:

pacaur -S wordplay

Of course there are lots of options so you can refine what you are lookind for, but in its simplest form, wordplay looks like this:

wordplay dragon
Wordplay Version 7.22 03-20-96, 1991 by Evans A Criswell
University of Alabama in Huntsville criswell@XX.XXX.edu

Candidate word list : no
Anagram Generation : yes
Adjacent duplicates : no
Vowel-free words OK : no

Max anagram depth : 32
Maximum word length : 128
Minimum word length : 0

Word list file : "/usr/share/wordplay/words721.txt"
String to anagram : "DRAGON"

Initializing. Please wait while words are being loaded
and unnecessary words are being filtered out ...

42 words loaded (4096 byte block). Longest kept: 6 letters.

Anagrams found:
1. DANG OR
2. DRAGON
3. GRAD ON
4. GRAD NO
5. DRAG ON
6. DRAG NO
7. RAND GO
8. DARN GO
9. NAG ROD
10. RANG DO
11. RAG NOD
12. RAG DON
13. RAN GOD
14. RAN DOG

Note I Xed out the email address. I have no clue if it is still in use, but I don’t want to send anyone spam because of an article here. Armed with these powerful word tools, you should be able to do pretty much anything you need right from the CLI without bothering to open a browser. If you have any other useful tips for word related command line apps, please leave a comment. Thanks for reading.

  • Tip Jar