From f1a81cb18932662814dd1abae152dd899303b8ab Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 24 Apr 2017 03:06:31 -0400 Subject: [PATCH] bin/spell: make more sophisticated --- bin/spell | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/bin/spell b/bin/spell index cb35c080..919851d5 100755 --- a/bin/spell +++ b/bin/spell @@ -1,2 +1,24 @@ #!/usr/bin/env bash -echo "$@" | aspell -a | tail -n-2 \ No newline at end of file + +# 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