diff options
-rw-r--r-- | hangman-helper.sh | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/hangman-helper.sh b/hangman-helper.sh index 3d14a7e..d6bf0ef 100644 --- a/hangman-helper.sh +++ b/hangman-helper.sh @@ -1,15 +1,24 @@ #!/bin/bash +# Usage: hangman-helper word not [-l] +# <word> is the known word, with unknown characters replaced with '.'. +# <not> is a sequence of the characters that are known to not be in the word. +# +# Without the `-l` flag, it produces a list of possible completions. +# +# Witht the `-l` flag, it produces a list of letters, +# sorted by the number of times they appear in the normal list + word=$1 not=$2 flag=$3 -temp=`mktemp` +temp="$(mktemp --tmpdir "${0##*/}.XXXXXXXXXX")" +trap "rm -f -- $(printf '%q' "$temp")" EXIT -grep -i '^'"$word"'$' /usr/share/dict/words | grep -iv "['$not]" > "$temp" +grep -ix "$word" /usr/share/dict/words | grep -iv "['$not]" > "$temp" -if [ "$flag" = '-l' ]; then +if [[ "$flag" = '-l' ]]; then cat "$temp" | tr 'A-Z' 'a-z' | sed 's/\(.\)/\1\n/'g | sort | uniq -c | sort -n else cat "$temp" fi -rm "$temp" |