aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/portmanteau
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/portmanteau')
-rwxr-xr-x.local/bin/portmanteau38
1 files changed, 38 insertions, 0 deletions
diff --git a/.local/bin/portmanteau b/.local/bin/portmanteau
new file mode 100755
index 0000000..9ce9dc3
--- /dev/null
+++ b/.local/bin/portmanteau
@@ -0,0 +1,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