summaryrefslogtreecommitdiff
path: root/hangman-helper.sh
blob: c46bb1e0af50df1ee11cddf2fce1cad5285fdb9f (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@sbcglobal.net>

# 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
}