From 666ab10eb40ad3f835663cc4eec085788e22a5d8 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 5 Dec 2013 01:18:18 -0500 Subject: hangman-helper: clean up --- hangman-helper.sh | 17 +++++++++++++---- 1 file 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] +# is the known word, with unknown characters replaced with '.'. +# 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" -- cgit v1.2.3