typie | Minimal typing practice tool |
| download: https://git.y1.nz/archives/typie.tar.gz | |
| README | Files | Log | Refs | LICENSE |
examples/words-by-letter.sh
1 #!/bin/sh
2
3 # generates words given a series of letters and symbols.
4 # uses a dictionary to find whole words,
5 # or else just randomly picks a chunk of letters.
6
7 CHARSET=$1
8 MIN_LENGTH=$2
9 MAX_LENGTH=$3
10 DICTFILE="./dict.txt"
11
12 if [ $MAX_LENGTH = "" ]; then
13 echo "Usage: words-by-letter.sh CHARSET MIN_LEN MAX_LEN"
14 exit 1
15 fi
16
17 # filter the dictionary for words only involving the characters, len >= 5.
18 WORDS="$(cat $DICTFILE | egrep "^[$CHARSET]{5,}$")"
19
20 LENGTH="$(seq $MIN_LENGTH $MAX_LENGTH | shuf -n 1)"
21 WORD_COUNT="$(echo "$WORDS" | wc -l)"
22 FEW_WORDS="false"
23 if [ "$WORD_COUNT" -lt "$LENGTH" ]; then
24 FEW_WORDS="true"
25 fi
26
27 get_jumble() {
28 ./letters.sh "$CHARSET" 4 6
29 }
30
31 get_word() {
32 echo "$WORDS" | shuf -n 1
33 }
34
35 get_symbol() {
36 echo " $(echo $SYMBOLS | sed 's/./ /g')$SYMBOLS" | fold -b -w 1 | shuf -n 1
37 }
38
39 PROMPT="$(get_jumble)"
40 for i in $(seq $LENGTH); do
41 if [ $FEW_WORDS = "true" ]; then
42 PROMPT="$PROMPT$(get_symbol)$(get_jumble)"
43 else
44 PROMPT="$PROMPT$(get_symbol)$(get_word)"
45 fi
46 done
47 echo "$PROMPT"
48
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.