riazj.com

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

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/&#9;.*//g" wn.index | sort -n &gt; wn.tmp &amp;& 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 &lt; $XDG_STATE_HOME/wn.index)" &gt; $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/&lt;ldquo\//&lt;q&gt;/g; s/&lt;rdquo\//&lt;\/q&gt;/g" "$1" &gt; tmp &amp;& mv tmp "$1" || rm tmp' echo {} \;
     35 sed "s/&lt;ent&gt; /&lt;ent&gt;/" K &gt; K.tmp &amp;& 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/&lt;cced\//ç/g; s/&lt;Cced\//Ç/" "$1" &gt; tmp &amp;& 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" ] &amp;& { 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 "&lt;ent&gt;$phrase&lt;/ent&gt;" "$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 "/&lt;ent&gt;$phrase&lt;\/ent&gt;/I,/^$/p")"
     60 [ "$thorough" ] &amp;& [ -z "$definitions" ] &amp;& {
     61   search_files="$(grep -irl "&lt;ent&gt;$phrase&lt;/ent&gt;" "$DICT")"
     62   definitions="$(printf "%s\n" "$search_files" | xargs sed -n "/&lt;ent&gt;$phrase&lt;\/ent&gt;/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 "&lt;ent&gt;.*&lt;/ent&gt;" "$DICT" |
     74   sed "s/&lt;.\?ent&gt;//g" | sort -n | uniq &gt; "$CACHE"
     75 
     76 dmenu -i -l 10 &lt; "$CACHE" | def -t
     77 </pre></article>
     78 <footer>
     79 <hr>
     80 <a href="/">Home Page</a></footer>
     81 </body>
     82 </html>