bin/spell: make more sophisticated

This commit is contained in:
Henrik Lissner 2017-04-24 03:06:31 -04:00
parent fa3e84b7a8
commit f1a81cb189

View file

@ -1,2 +1,24 @@
#!/usr/bin/env bash #!/usr/bin/env bash
echo "$@" | aspell -a | tail -n-2
# A simple script for correcting the spelling of a word. Uses (and requires) fzf
# to select the correct word. This output can be piped to something like dict
#
# Usage: spell mispeling
# Example: dict $(spell mispeling)
result=$(echo "$@" | aspell -a | tail -n-2)
if [[ "$result" == '*' ]]; then
echo "$@"
else
if ! command -v 'fzf' >/dev/null; then
>&2 echo "fzf not installed"
exit 1
fi
words=$(echo "$result" | sed 's/[:,] /\n/g' | tail -n +2)
if (( $(wc -l <<< "$words") > 1 )); then
fzf <<< "$words"
else
echo "$words"
fi
fi