From c232cc208281078f2fae1d2047fa582c28e81cc5 Mon Sep 17 00:00:00 2001 From: Anton Bobov Date: Mon, 20 Apr 2026 13:17:50 +0500 Subject: add words script for generating random dictionary words --- words | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 words diff --git a/words b/words new file mode 100755 index 0000000..4516a1a --- /dev/null +++ b/words @@ -0,0 +1,31 @@ +#!/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" "$@")" -- cgit v1.2.3