dictionaries.html (3290B)
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 dict "$(dmenu -i -l 10 < $XDG_STATE_HOME/wn.index)" > $XDG_RUNTIME_DIR/dmenu_dict; \ 27 st less -+F -c $XDG_RUNTIME_DIR/dmenu_dict 28 </pre> 29 <p>I no longer use the following hacky setup with GCIDE. Its custom markup sucks.</p> 30 <pre> 31 cd gcide 32 for f in CIDE*; do; mv $f "${f#*.}"; done 33 mkdir info; find -maxdepth 1 -type f -not -name "?" -exec mv {} info \; 34 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 {} \; 35 sed "s/<ent> /<ent>/" K > K.tmp && mv K.tmp K 36 def word # or dmenu_def, shell scripts below, licensed under BSD0 37 # repeat the following to replace GCIDE's non-standard markup while referencing webfont.txt 38 find -maxdepth 1 -type f -exec sh -c 'sed "s/<cced\//ç/g; s/<Cced\//Ç/" "$1" > tmp && mv tmp "$1" || rm tmp' echo {} \; 39 </pre> 40 <pre> 41 #!/bin/sh -e 42 43 DICT="$HOME/data/books/dictionary" 44 45 phrase="${*:-$(cat)}" 46 # e.g. gum ammoniac is with dictionary entries that start with A 47 [ "$phrase" = "-t" ] && { thorough=1; phrase="$(cat)"; } 48 phrase="$(printf "%s" "$phrase" | tr '[:lower:]' '[:upper:]' | sed 's=\\=\\\\=g; s=\/=\\\/=g')" 49 50 letter="$(printf "%.1s" "$phrase")" 51 case "$letter" in 52 "'") end="${phrase#?}"; letter="${end%"${end#?}"}" ;; # second char 53 "-") search_files="$(grep -irl "<ent>$phrase</ent>" "$DICT")" ;; 54 ".") letter="V" ;; 55 [0-9]|"\\") letter="A" ;; 56 esac 57 58 : "${search_files="$DICT/$letter"}" 59 definitions="$(printf "%s\n" "$search_files" | xargs sed -n "/<ent>$phrase<\/ent>/I,/^$/p")" 60 [ "$thorough" ] && [ -z "$definitions" ] && { 61 search_files="$(grep -irl "<ent>$phrase</ent>" "$DICT")" 62 definitions="$(printf "%s\n" "$search_files" | xargs sed -n "/<ent>$phrase<\/ent>/I,/^$/p")" 63 } 64 65 printf "%s" "$definitions" | w3m -dump -T text/html 66 </pre> 67 <pre> 68 #!/bin/sh -e 69 70 DICT="$HOME/data/books/dictionary" 71 CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/dmenu_def" 72 73 [ -f "$CACHE" ] || grep -orh --exclude-dir=info "<ent>.*</ent>" "$DICT" | 74 sed "s/<.\?ent>//g" | sort -n | uniq > "$CACHE" 75 76 dmenu -i -l 10 < "$CACHE" | def -t 77 </pre></article> 78 <footer> 79 <hr> 80 <a href="/">Home Page</a></footer> 81 </body> 82 </html>