function friendly-name --description "Emit random friendly adjective-noun names" argparse 'h/help' 'n/count=' 'e/exclude=' 'exclude-file=' 'exclude-stdin' -- $argv or return 1 if set -q _flag_help echo "Usage: friendly-name [OPTIONS]" echo echo "Emit random friendly adjective-noun names." echo echo "Options:" echo " -n, --count COUNT Number of names to emit (default: 1)" echo " -e, --exclude NAME Exclude a specific name; may be repeated" echo " --exclude-file PATH Read newline-delimited excludes from file" echo " --exclude-stdin Read newline-delimited excludes from stdin" echo " -h, --help Show this help message" return 0 end set -l adjectives \ ancient autumn bitter billowing black blue bold brave broken calm \ clever cold cool crimson damp dark dawn delicate dry eager \ empty falling fragrant frosty fuzzy gentle golden green hidden holy \ icy keen late light lingering little lively long lucky merry \ misty muddy nameless noble old patient purple quiet red rough \ shy silent small sparkling spring steady still swift twilight wandering \ warm weathered white wild winter wispy withered young zippy \ bright brisk crystal dusty faint fierce floral free fresh \ great happy high huge kind loud majestic mild pale \ pleasant polished proud quick ripe rolling rose royal \ serene sharp silver sleek smooth snowy soft spiced \ stout strange strong summer sunny sweet tall tender \ tiny vast velvet vivid wide wondrous set -l nouns \ aurora badger beagle breeze brook cabin canyon cedar cliff cloud \ comet coral crane creek delta dew dune eagle ember feather \ fern field finch fire flora forest fox frog frost gazelle \ glacier grass grove haven haze hill island kite lagoon lake \ leaf lemur lily lynx marsh meadow mesa mist moon moose \ mountain oak oasis otter owl panda peak pebble pine pond \ rain ridge ripple river shadow sky smoke snow star stone \ stream sun thunder tree tundra valley vortex wave wind \ ash basin bear birch bloom blossom boulder cherry \ cove crystal daisy deer echo elk fawn flame flower \ gale garden geode glen gorge gull hawk heron iris \ ivy jay jewel lark loon lotus lupine maple moss \ nest orchid osprey path petal plum poppy prairie \ quartz quail rabbit reef robin rose sage sail sequoia \ shell shore shrew sparrow spruce storm summit swallow \ swan swift thistle thorn thrush tide trail trout \ tulip violet willow wing wren set -l count 1 if set -q _flag_count set count $_flag_count if not string match -qr '^[1-9][0-9]*$' -- $count echo "friendly-name: --count must be a positive integer" >&2 return 1 end end set -l excludes if set -q _flag_exclude set -a excludes $_flag_exclude end if set -q _flag_exclude_file if not test -r "$_flag_exclude_file" echo "friendly-name: cannot read exclude file '$_flag_exclude_file'" >&2 return 1 end while read -l line test -n "$line"; and set -a excludes $line end <"$_flag_exclude_file" end if set -q _flag_exclude_stdin while read -l line test -n "$line"; and set -a excludes $line end end set -l max_combinations (math (count $adjectives) \* (count $nouns)) if test (math $max_combinations - (count $excludes)) -lt $count echo "friendly-name: not enough unique combinations available" >&2 return 1 end set -l emitted set -l emitted_count 0 set -l max_attempts 1000 while test $emitted_count -lt $count set -l attempts 0 while true set -l adjective $adjectives[(random 1 (count $adjectives))] set -l noun $nouns[(random 1 (count $nouns))] set -l name "$adjective-$noun" if contains -- $name $excludes; or contains -- $name $emitted set attempts (math $attempts + 1) if test $attempts -ge $max_attempts echo "friendly-name: could not generate a unique name after $max_attempts attempts" >&2 return 1 end continue end echo $name set -a emitted $name set emitted_count (math $emitted_count + 1) break end end end