dict, thes & ency

This is a very old article. It has been imported from older blogging software, and the formatting, images, etc may have been lost. Some links may be broken. Some of the information may no longer be correct. Opinions expressed in this article may no longer be held.

dict is a command that is supplied with most Linux and BSD distributions. If you enter dict foo at the command-line, you get back the dictionary definition of “foo”. Normally several different dictionaries are supplied, including some dictionaries of translation, and it’s possible to look up the word on various online dictionaries too.

As counterparts to dict I’ve created thes for looking stuff up in Moby’s Thesaurus and ency for online encyclopaedia Wikipedia.

thes

thes requires dict to be installed and working correctly.

#!/bin/sh
/usr/bin/dict -d moby-thes -h dict.org “$1”

OK — maybe it’s a little over-simplistic, but it does the job.

ency

ency requires Lynx, Perl and a working Internet connection.

#!/usr/bin/perl

$_ = shift @ARGV || die “Need to supply an argument.\n”;
s/\s+/_/g;
$_ = URLEncode(ucfirst($_));
s/\’/\\\’/g; # Fix syntax highlighting: ‘
$url = ‘http://en.wikipedia.org/wiki/’.$_;
$page = `lynx -nolist -dump -justify=0 ‘$url’`;

if ($page =~ /Wikipedia does not have an article with this exact name\./)
{
print “Article not found.\n”;
exit;
}

($page, $dummy) = split /\nViews\n/, $page;
@lines = split /\n/, $page;
shift @lines;
shift @lines;

foreach (@lines)
{
s/^\[edit\]\s+?//;
print “$_\n”;
}

sub URLEncode {
$_ = shift;
s/([\W])/”%” . uc(sprintf(“%2.2x”,ord($1)))/eg;
return $_;
}

I hope someone finds these useful.