how to use dmenu to look up words at dict.leo.org on Archlinux


Install Perl/CPAN module WWW::Dict::Leo::Org. If you’re on Archlinux install perl-www-dict-leo-org-systemfreund from AUR.

A shell-script named leo will be installed at /usr/bin/vendor_perl/leo. Here’s an example output:

~ » leo test
Found 41 matches for 'test' on dict.leo.org:

Substantive
 test                                                          die Prüfung  Pl.: die Prüfungen
 test                                                          der Test  Pl.: die Tests/die Teste
 check                                                         der Test  Pl.: die Tests/die Teste
 test   also  [tech.]                                       der Versuch  Pl.: die Versuche
 test                                                          die Untersuchung  Pl.: die Untersuchungen

Unfortunately we cannot use the script with dmenu without additional help. Let’s write a wrapper script with the same name and save it in /usr/local/bin/leo. On my machine /usr/local/bin has precedence over /usr/bin/vendor_perl therefore we’re going to use that location to override the original script:

#!/bin/bash

QUERY="$@"
/usr/bin/vendor_perl/leo -n "$QUERY" 2>&1 | dmenu

Dmenu ignores color codes, hence the -n switch to leave them out in the first place. Let’s see the what we’ve got now:

leo-screenshot-1

This doesn’t look right. It seems every line is cut off at the first encounter of an umlaut or any other ‘unusual’ character, like ü in this example. Apparently the response body of dict.leo.org is not encoded in UTF-8, but in ISO-8859-1 (aka latin1) which causes trouble in dmenu. If you’re also running into this problem let’s add an additional step to our wrapper script by using iconv to convert the encoding:

#!/bin/bash

QUERY="$@"
/usr/bin/vendor_perl/leo -n "$QUERY" 2>&1 | iconv -c -f iso-8859-1 -t utf-8 | dmenu

Looks better now in dmenu!