summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2013-12-05 01:18:18 -0500
committerLuke Shumaker <LukeShu@sbcglobal.net>2013-12-05 01:18:18 -0500
commit666ab10eb40ad3f835663cc4eec085788e22a5d8 (patch)
tree67314ce17d041d516525a4073ee7b198c4c152da
parent05dd6877526fc388c6ecbd03e3483636ab2c4e86 (diff)
hangman-helper: clean up
-rw-r--r--hangman-helper.sh17
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"