From 6518aebaf6570c370753c4bae83d38664c1f7b2a Mon Sep 17 00:00:00 2001 From: tdro Date: Tue, 21 Mar 2023 17:10:55 -0400 Subject: .local/bin/portmanteau: Improve --- .local/bin/portmanteau | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/.local/bin/portmanteau b/.local/bin/portmanteau index a3788c8..9ce9dc3 100755 --- a/.local/bin/portmanteau +++ b/.local/bin/portmanteau @@ -1,10 +1,38 @@ -#!/bin/sh -eu -word=$(diceware --no-caps --num 2 --delimiter " ") -first=${word%??? *} -second=${word#* ???} +#!/usr/bin/env bash +set -eu -# TODO: Maybe manipulate adjacent consonants and vowels at the word merge boundary. -# barric[ade] [hea]dlock -# barri[cd]lock -> barrilock +minimum=4 +words=$(diceware --no-caps --num 2 --delimiter " ") +first=${words%??? *} +second=${words#* ???} -printf '%s\n%s%s\n' "$word" "$first" "$second" +[ ${#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 -- cgit v1.2.3