blob: 9ce9dc3e31d60bd9d4443ba3dc73a654bb586e5e (
plain)
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
|
#!/usr/bin/env bash
set -eu
minimum=4
words=$(diceware --no-caps --num 2 --delimiter " ")
first=${words%??? *}
second=${words#* ???}
[ ${#first} -lt $minimum ] && "$0" && exit
[ ${#second} -lt $minimum ] && "$0" && exit
vowels="a e i o u"
sounds="h r w y"
consonants="b c d f g j k l m n p q s t v x z"
suffix=${first: -1:1}
prefix=${second: 0:1}
digraph="$suffix$prefix"
compressed="${first: 0:-1}${second: 1}"
printf 'words: %s\n' "$words"
printf 'digraph: %s\n' "$digraph"
printf 'merge: %s%s\n' "$first" "$second"
printf 'compressed: %s\n\n' "$compressed"
Grammar() {
for left in $consonants; do
[ "$suffix" = "$left" ] &&
{
for right in $consonants; do
[ "$prefix" = "$right" ] &&
printf '%s\n' "$compressed" &&
exit
done
}
done || printf '%s%s\n' "$first" "$second"
}
Grammar
|