summaryrefslogtreecommitdiff
path: root/hangman-helper.sh
blob: 28f9d1162fb9eeb828806f2716b49f32c5e018b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash
# Copyright (C) 2011, 2013-2014 Luke Shumaker <lukeshu@lukeshu.com>

# 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.
#
# With the `-l` flag, it produces a list of letters not in <word>,
# sorted by the number of times they appear in the normal list

word=$1
not=$2
flag=$3

grep -ix "$word" /usr/share/dict/words | grep -iv "['$not]" | {
	if [[ "$flag" = '-l' ]]; then
		tr 'A-Z' 'a-z' | sed 's/\(.\)/\1\n/'g | grep -v -e "[$word]" -e '^$' | sort | uniq -c | sort -n
	else
		sort
	fi
}