dictionaries.html (3590B)
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="utf-8"> 5 <title>Notes on Offline English Dictionaries | Riaz's Website</title> 6 <link rel="stylesheet" href="/style.css"> 7 <link rel="icon" href="data:,"> 8 <meta name="description" content="Notes on offline English dictionaries with dictd or a shell script for GCIDE"> 9 <meta name="viewport" content="width=device-width, initial-scale=1"> 10 </head> 11 <body> 12 <h1>Notes on Offline English Dictionaries</h1> 13 <hr> 14 <article> 15 <p><a href="https://wiki.archlinux.org/title/Dictd">Install dictd, and configure it to use offline dictionaries.</a></p> 16 <p>To use dict with dmenu, create an index. The following assumes that you are using the WordNet dictionary.</p> 17 <pre> 18 cd ~/.local/state 19 cp /usr/share/dictd/wn.index . 20 sed "s/	.*//g" wn.index | sort -n > wn.tmp && mv wn.tmp wn.index 21 </pre> 22 <p>Note that in the sed command above, there is a tab, but your browser might show a space. If you copy it to your clipboard, it should work regardless.</p> 23 <p>To use this with sxhkd:</p> 24 <pre> 25 alt + shift + d 26 definition="$XDG_RUNTIME_DIR/dmenu_dict"; \ 27 dict "$(dmenu -i -l 10 < $XDG_STATE_HOME/wn.index)" > "$definition"; \ 28 [ -s "$definition" ] && st less -+F -c "$definition" 29 </pre> 30 <p>2025 Aug 8th: I switched back to sdcv since the AUR has a repository with only the WordNet files without its programs.</p> 31 <pre> 32 alt + d 33 def="$XDG_RUNTIME_DIR/sdcv"; \ 34 sdcv -n "$(:|dmenu -p "Define:")" > "$def"; \ 35 [ -s "$def" ] && st less "$def" 36 </pre> 37 <p>I no longer use the following hacky setup with GCIDE. Its custom markup sucks.</p> 38 <pre> 39 cd gcide 40 for f in CIDE*; do; mv $f "${f#*.}"; done 41 mkdir info; find -maxdepth 1 -type f -not -name "?" -exec mv {} info \; 42 find -maxdepth 1 -type f -exec sh -c 'sed "s/<ldquo\//<q>/g; s/<rdquo\//<\/q>/g" "$1" > tmp && mv tmp "$1" || rm tmp' echo {} \; 43 sed "s/<ent> /<ent>/" K > K.tmp && mv K.tmp K 44 def word # or dmenu_def, shell scripts below, licensed under BSD0 45 # repeat the following to replace GCIDE's non-standard markup while referencing webfont.txt 46 find -maxdepth 1 -type f -exec sh -c 'sed "s/<cced\//ç/g; s/<Cced\//Ç/" "$1" > tmp && mv tmp "$1" || rm tmp' echo {} \; 47 </pre> 48 <pre> 49 #!/bin/sh -e 50 51 DICT="$HOME/data/books/dictionary" 52 53 phrase="${*:-$(cat)}" 54 # e.g. gum ammoniac is with dictionary entries that start with A 55 [ "$phrase" = "-t" ] && { thorough=1; phrase="$(cat)"; } 56 phrase="$(printf "%s" "$phrase" | tr '[:lower:]' '[:upper:]' | sed 's=\\=\\\\=g; s=\/=\\\/=g')" 57 58 letter="$(printf "%.1s" "$phrase")" 59 case "$letter" in 60 "'") end="${phrase#?}"; letter="${end%"${end#?}"}" ;; # second char 61 "-") search_files="$(grep -irl "<ent>$phrase</ent>" "$DICT")" ;; 62 ".") letter="V" ;; 63 [0-9]|"\\") letter="A" ;; 64 esac 65 66 : "${search_files="$DICT/$letter"}" 67 definitions="$(printf "%s\n" "$search_files" | xargs sed -n "/<ent>$phrase<\/ent>/I,/^$/p")" 68 [ "$thorough" ] && [ -z "$definitions" ] && { 69 search_files="$(grep -irl "<ent>$phrase</ent>" "$DICT")" 70 definitions="$(printf "%s\n" "$search_files" | xargs sed -n "/<ent>$phrase<\/ent>/I,/^$/p")" 71 } 72 73 printf "%s" "$definitions" | w3m -dump -T text/html 74 </pre> 75 <pre> 76 #!/bin/sh -e 77 78 DICT="$HOME/data/books/dictionary" 79 CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/dmenu_def" 80 81 [ -f "$CACHE" ] || grep -orh --exclude-dir=info "<ent>.*</ent>" "$DICT" | 82 sed "s/<.\?ent>//g" | sort -n | uniq > "$CACHE" 83 84 dmenu -i -l 10 < "$CACHE" | def -t 85 </pre></article> 86 <footer> 87 <hr> 88 <a href="/">Home Page</a></footer> 89 </body> 90 </html>