4

Is there some way to list all available dictionaries in hunspell? Something like aspell dump dicts. printf | hunspell -D prints too much junk, and I want to query hunspell itself, not do something like find /usr/share/myspell/dicts/ -name '*.dic' | cut -d '/' -f 6 | cut -d '.' -f 1 | sort.

Jonas Stein
  • 3,898
  • 4
  • 34
  • 55
l0b0
  • 50,672
  • 41
  • 197
  • 360
  • You could look into [pyenchant](http://pythonhosted.org/pyenchant/), e.g. a basic example: `python -c 'import enchant;print(*enchant.list_dicts(), sep="\n")'`. – don_crissti Feb 28 '15 at 17:21

1 Answers1

4

How about this:

LANG=C </dev/null hunspell -D|&sed -n '/AVAILABLE DICTIONARIES/,/LOADED DICTIONARIES/p'|awk -F / '/\// { print $NF }'|sort -u

This drops the hunspell search path from the output and lists only available dictionary names. If you want to remove hyphenation dictionaires you can add |grep -v hyph...

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
  • Nice, but this gets a bit kludgy if you want it to be reliable: It needs an `echo |` at the start to terminate the input stream, it should handle the case of no dictionaries (Is there a heading in that case?) or a single dictionary (Is that heading singular?), and it needs to stop before the `LOADED DICTIONARY` line if it exists (or EOF if it doesn't). – l0b0 Mar 01 '15 at 09:37
  • Looking at the source code, there always is an "AVAILABLE DICTIONARIES" heading even if no dictionaries are installed, and it doesn't change for a single dictionary; but it is locale-dependent. I'll update my answer accordingly (and with `< /dev/null` to handle the input stream). – Stephen Kitt Mar 01 '15 at 17:33