f2a4b2b17bbf9103dd90d23a73163e9b4e0e47f1
- Author
- Marc Cornellà <marc.cornella@live.com>
- Committer
- Marc Cornellà <marc.cornella@live.com>
- Date
Message
fix(genpass): in `genpass-xkcd`, add warnings and make it compatible with macOS
Closes #9515
Closes #9516
Diff
1diff --git a/plugins/genpass/genpass.plugin.zsh b/plugins/genpass/genpass.plugin.zsh
2index e7f86bf7a1a4dd46ba0426e9152f21b4212dad37..e6a1cef348ff2611fcfa4c207b638d6521358357 100644
3--- a/plugins/genpass/genpass.plugin.zsh
4+++ b/plugins/genpass/genpass.plugin.zsh
5@@ -73,8 +73,19 @@ genpass-monkey() {
6
7 genpass-xkcd() {
8 # Generates a 128-bit XKCD-style passphrase
9- # EG, 9-mien-flood-Patti-buxom-dozes-ickier-pay-ailed-Foster
10+ # e.g, 9-mien-flood-Patti-buxom-dozes-ickier-pay-ailed-Foster
11 # Can take a numerical argument for generating extra passwords
12+
13+ if (( ! $+commands[shuf] )); then
14+ echo >&2 "$0: \`shuf\` command not found. Install coreutils (\`brew install coreutils\` on macOS)."
15+ return 1
16+ fi
17+
18+ if [[ ! -e /usr/share/dict/words ]]; then
19+ echo >&2 "$0: no wordlist found in \`/usr/share/dict/words\`. Install one first."
20+ return 1
21+ fi
22+
23 local -i i num
24
25 [[ $1 =~ '^[0-9]+$' ]] && num=$1 || num=1
26@@ -90,6 +101,6 @@ genpass-xkcd() {
27
28 for i in {1..$num}; do
29 printf "$n-"
30- printf "$dict" | shuf -n "$n" | paste -sd '-'
31+ printf "$dict" | shuf -n "$n" | paste -sd '-' -
32 done
33 }