blob: 4516a1a5cfe4711c4552e0a72283df699ec619c2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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" "$@")"
|