-
Notifications
You must be signed in to change notification settings - Fork 0
/
words-bingo.sh
executable file
·78 lines (64 loc) · 1.96 KB
/
words-bingo.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
wordlist_filename=${1:-my-words.txt}
used_words_filename=.used-$(basename $wordlist_filename)
espeak_command="espeak -v en-us"
word_echo_command="cowsay" # default is "echo"
list_all_words() {
cat $wordlist_filename | sort -u
}
list_used_words() {
cat $used_words_filename | sort -u
}
list_left_words() {
list_all_words | \
comm -23 - <(list_used_words)
}
# is there a wordlist?
if [ ! -f $wordlist_filename ]; then
echo -e "\e[31mError\e[0m: Please provide \"$wordlist_filename\""
exit 1
fi
# ensure used words file exists
touch $used_words_filename
# as long as we have unused words in the list
while [ 0 -lt "$(list_left_words | wc -l)" ]; do
clear
echo -e "\e[33m"
word=$(list_left_words | \
shuf -n 1)
echo $word >> $used_words_filename
$word_echo_command $word
echo -e "\e[0m"
echo
used_words=$(list_used_words | wc -l)
unused_words=$(list_left_words | wc -l)
total_words=$(($used_words + $unused_words))
echo -e "\e[36mHint\e[0m: Unused words: \e[32m$unused_words\e[0m, total words: \e[33m$total_words\e[0m, used words: \e[31m$used_words\e[0m"
if [ -n "$espeak_command" ]; then
counter=0
while : ; do
$espeak_command "$word"
# wait for user input...
[ $counter -eq 0 ] && echo '
r ........ repeat current word
ENTER .... next random word
q ........ quit program'
read -n1 -p "" user_input
((counter++))
[ "$user_input" == "r" ] && continue
[ "$user_input" == "q" ] && { echo; exit 0; }
break
done
else
# wait for user input...
echo '
ENTER .... next random word
q ........ quit program'
read -p "" user_input
[ "$user_input" == "q" ] && { echo; exit 0; }
fi
done
# all words used up
echo
echo -e "\e[36mHint\e[0m: All words from \"$wordlist_filename\" are used up"
echo " Please use \"rm $used_words_filename\" to start over"