summaryrefslogtreecommitdiff
path: root/words
diff options
context:
space:
mode:
authorAnton Bobov <anton@bobov.name>2026-04-20 13:17:50 +0500
committerAnton Bobov <anton@bobov.name>2026-07-24 14:21:45 +0500
commitc232cc208281078f2fae1d2047fa582c28e81cc5 (patch)
treeabd3eb6ec625917d383a3cda0afd82e6f4db35ee /words
parentb11137b123c51126e8a826fdd011e0cba81e0b51 (diff)
add words script for generating random dictionary words
Diffstat (limited to 'words')
-rwxr-xr-xwords31
1 files changed, 31 insertions, 0 deletions
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" "$@")"