#!/usr/bin/env bash set -euo pipefail # @describe Generates random words of specified length from dictionary # @meta require-tools grep,tr,shuf # @flag -1 one word per line # @option -l --length=8, Length of each generated word (in regexp format) # @option -n --words=1 Number of words to generate # @arg pattern regular expression pattern # @env WORDS_FILE=/usr/share/dict/words Path to dictionary file _list_words() { iconv -t ASCII//TRANSLIT "$WORDS_FILE" | # Fix accents (like ö, ü, é) grep -xE "[a-zA-Z]{${argc_length?}}" | tr '[:upper:]' '[:lower:]' | grep -E "${argc_pattern:-}" | shuf -n "${argc_words?}" } main() { mapfile -t words < <(_list_words) if [ -n "${argc_1:-}" ]; then printf "%s\n" "${words[@]}" else printf "%s\n" "${words[*]}" fi } eval "$(argc --argc-eval "$0" "$@")"