diff options
Diffstat (limited to 'spelling/check-spelling.sh')
-rwxr-xr-x | spelling/check-spelling.sh | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/spelling/check-spelling.sh b/spelling/check-spelling.sh new file mode 100755 index 0000000..653a5f9 --- /dev/null +++ b/spelling/check-spelling.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +set -Eeuo pipefail + +HTML_DIR="${1:-}" +[[ -z "${HTML_DIR}" ]] && { + echo 'Undefined input HTML_DIR.' >&2 + exit 2 +} + +# Required by =sort= and =hunspell= +export LANG=C.UTF-8 + +for DICT in spelling/*.txt; do + diff <(sort "$DICT") "$DICT" || { + echo "The $DICT dictionary is unsorted. To fix it, run:" >&2 + echo " LANG=C.UTF-8 sort $DICT | sponge $DICT" >&2 + exit 1 + } +done + +finish() { + rm -f spelling.txt + rm -f dicts.txt +} +trap finish EXIT + +cat spelling/*.txt > dicts.txt + +find "${HTML_DIR}" -type f -name '*.html' | grep -v pastebin | hunspell -l -p dicts.txt -d fr_FR -d en_US -i utf-8 >> spelling.txt + +if [[ -s spelling.txt ]]; then + printf "\nvvv Mispelled words detected by hunspell.\n\n" >&2 + sort < spelling.txt | uniq >&2 + printf "\n^^^\n" >&2 + exit 1 +else + echo "No words mispelled" >&2 +fi |