riazj.com

source code for this website
git clone https://riazj.com/git/riazj.com
Log | Files | Refs | LICENSE

commit 6ae3fbab32bcd3d38ea52ec9250f11718bffbd64
parent 8481a98af186205c4ccf39b35cfe5729b9a128c0
Author: Riaz <riaz@riazj.com>
Date:   Tue, 22 Jul 2025 15:12:28 -0700

Use dictd instead of shell scripts for dictionaries

Diffstat:
Darticles/cli-dictionary.html | 27---------------------------
Aarticles/dictionaries.html | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mindex.html | 2+-
3 files changed, 82 insertions(+), 28 deletions(-)

diff --git a/articles/cli-dictionary.html b/articles/cli-dictionary.html @@ -1,27 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> -<head> -<meta charset="utf-8"> -<title>The Best Offline Command-Line English Dictionary | Riaz's Website</title> -<link rel="stylesheet" href="/style.css"> -<link rel="icon" href="data:,"> -<meta name="description" content="Using an offline copy of the GCIDE with a shell script is better than command-line dictionaries like sdcv"> -<meta name="viewport" content="width=device-width, initial-scale=1"> -</head> -<body> -<h1>The Best Offline Command-Line English Dictionary</h1> -<hr> -<article> -<p><a href="https://dushistov.github.io/sdcv/">sdcv</a> was once listed on my <a href="technology-i-use">recommended technologies page</a>; however, the process of downloading a dictionary for it is time-consuming.</p> -<p>To get a dictionary for sdcv, this excruciating long URL can be used: <a href="https://web.archive.org/web/20140917131745/http://abloz.com/huzheng/stardict-dic/dict.org/">https://web.archive.org/web/20140917131745/http://abloz.com/huzheng/stardict-dic/dict.org/</a>. This process is made further sluggish by the many user requests to the Internet Archive. There is no guarantee that the site will even be online when needed, as seen from the cyberattacks of May and October 2024.</p> -<p>A better alternative is to download the <a href="https://gcide.gnu.org.ua/download">GNU Collaborative International Dictionary of English</a>.</p> -<p>Once inside the unpacked directory, run the following to change the naming of the files from "CIDE.*" to single letters.</p> -<pre>for f in CIDE*; do; mv $f "${f#*.}"; done</pre> -<p>Now, <a href="/git/dotfiles/file/.local/bin/def">this shell script</a> can be used.</p> -<p>The w3m command can be replaced by other command-line web browsers to view the HTML. It takes less than a tenth of a second to return a definition.</p> -</article> -<footer> -<hr> -<a href="/">Home Page</a></footer> -</body> -</html> diff --git a/articles/dictionaries.html b/articles/dictionaries.html @@ -0,0 +1,81 @@ +<!DOCTYPE html> +<html lang="en"> +<head> +<meta charset="utf-8"> +<title>Notes on Offline English Dictionaries | Riaz's Website</title> +<link rel="stylesheet" href="/style.css"> +<link rel="icon" href="data:,"> +<meta name="description" content="Notes on offline English dictionaries with dictd or a shell script for GCIDE"> +<meta name="viewport" content="width=device-width, initial-scale=1"> +</head> +<body> +<h1>Notes on Offline English Dictionaries</h1> +<hr> +<article> +<p><a href="https://wiki.archlinux.org/title/Dictd">Install dictd, and configure it to use offline dictionaries.</a></p> +<p>To use dict with dmenu, create an index. The following assumes that you are using the WordNet dictionary:</p> +<pre> +cd ~/.local/state +cp /usr/share/dictd/wn.index . +sed "s/ .*//g" wn.index | sort -n &gt; wn.tmp &amp;& mv wn.tmp wn.index +</pre> +<p>To use this with sxhkd:</p> +<pre> +alt + shift + d + dict "$(dmenu -i -l 10 &lt; $XDG_STATE_HOME/wn.index)" &gt; $XDG_RUNTIME_DIR/dmenu_dict; \ + st less -+F -c $XDG_RUNTIME_DIR/dmenu_dict +</pre> +<p>I no longer use the following hacky setup with GCIDE. Its custom markup sucks.</p> +<pre> +cd gcide +for f in CIDE*; do; mv $f "${f#*.}"; done +mkdir info; find -maxdepth 1 -type f -not -name "?" -exec mv {} info \; +find -maxdepth 1 -type f -exec sh -c 'sed "s/&lt;ldquo\//&lt;q&gt;/g; s/&lt;rdquo\//&lt;\/q&gt;/g" "$1" &gt; tmp &amp;& mv tmp "$1" || rm tmp' echo {} \; +sed "s/&lt;ent&gt; /&lt;ent&gt;/" K &gt; K.tmp &amp;& mv K.tmp K +def word # or dmenu_def, shell scripts below, licensed under BSD0 +# repeat the following to replace GCIDE's non-standard markup while referencing webfont.txt +find -maxdepth 1 -type f -exec sh -c 'sed "s/&lt;cced\//ç/g; s/&lt;Cced\//Ç/" "$1" &gt; tmp &amp;& mv tmp "$1" || rm tmp' echo {} \; +</pre> +<pre> +#!/bin/sh -e + +DICT="$HOME/data/books/dictionary" + +phrase="${*:-$(cat)}" +# e.g. gum ammoniac is with dictionary entries that start with A +[ "$phrase" = "-t" ] &amp;& { thorough=1; phrase="$(cat)"; } +phrase="$(printf "%s" "$phrase" | tr '[:lower:]' '[:upper:]' | sed 's=\\=\\\\=g; s=\/=\\\/=g')" + +letter="$(printf "%.1s" "$phrase")" +case "$letter" in + "'") end="${phrase#?}"; letter="${end%"${end#?}"}" ;; # second char + "-") search_files="$(grep -irl "&lt;ent&gt;$phrase&lt;/ent&gt;" "$DICT")" ;; + ".") letter="V" ;; + [0-9]|"\\") letter="A" ;; +esac + +: "${search_files="$DICT/$letter"}" +definitions="$(printf "%s\n" "$search_files" | xargs sed -n "/&lt;ent&gt;$phrase&lt;\/ent&gt;/I,/^$/p")" +[ "$thorough" ] &amp;& [ -z "$definitions" ] &amp;& { + search_files="$(grep -irl "&lt;ent&gt;$phrase&lt;/ent&gt;" "$DICT")" + definitions="$(printf "%s\n" "$search_files" | xargs sed -n "/&lt;ent&gt;$phrase&lt;\/ent&gt;/I,/^$/p")" +} + +printf "%s" "$definitions" | w3m -dump -T text/html +</pre> +<pre> +#!/bin/sh -e + +DICT="$HOME/data/books/dictionary" +CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/dmenu_def" + +[ -f "$CACHE" ] || grep -orh --exclude-dir=info "&lt;ent&gt;.*&lt;/ent&gt;" "$DICT" | + sed "s/&lt;.\?ent&gt;//g" | sort -n | uniq &gt; "$CACHE" + +dmenu -i -l 10 &lt; "$CACHE" | def -t +</pre></article> +<footer> +<hr> +<a href="/">Home Page</a></footer> +</body> +</html> diff --git a/index.html b/index.html @@ -16,7 +16,7 @@ <h2>Articles</h2> <ul> <li><time datetime="2025-07-19">2025 Jul 19</time> <a href="/articles/tldr">Simple TLDR Client Written in POSIX Shell</a></li> -<li><time datetime="2025-06-08">2025 Jun 08</time> <a href="/articles/cli-dictionary">The Best Offline Command-Line English Dictionary</a></li> +<li><time datetime="2025-06-08">2025 Jun 08</time> <a href="/articles/dictionaries">Notes on Offline English Dictionaries</a></li> <li><time datetime="2025-02-27">2025 Feb 27</time> <a href="/articles/format-html">I Quit Using Prettier to Format HTML</a></li> <li><time datetime="2024-12-06">2024 Dec 06</time> <a href="/articles/powerschool-absence">Unable to Submit PowerSchool Absence Reports</a></li> <li><time datetime="2024-11-09">2024 Nov 09</time> <a href="/articles/installing-alpine-linux">Notes on Installing Alpine Linux</a></li>