summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Cornellà <marc.cornella@live.com>2020-12-14 15:47:00 +0100
committerMarc Cornellà <marc.cornella@live.com>2020-12-14 15:52:32 +0100
commitf2a4b2b17bbf9103dd90d23a73163e9b4e0e47f1 (patch)
tree6630dc75945d3db64d1101283a7e392c45f3941f
parent2a0ae3315db98d137de547e2cb9adfbc38263e6c (diff)
parent2db42c6ce745ed37262bed6c97683a00a430f076 (diff)
downloadzsh-f2a4b2b17bbf9103dd90d23a73163e9b4e0e47f1.tar.gz
zsh-f2a4b2b17bbf9103dd90d23a73163e9b4e0e47f1.tar.bz2
zsh-f2a4b2b17bbf9103dd90d23a73163e9b4e0e47f1.zip
fix(genpass): in `genpass-xkcd`, add warnings and make it compatible with macOS
Closes #9515 Closes #9516
-rw-r--r--plugins/genpass/genpass.plugin.zsh15
1 files changed, 13 insertions, 2 deletions
diff --git a/plugins/genpass/genpass.plugin.zsh b/plugins/genpass/genpass.plugin.zsh
index e7f86bf7a..e6a1cef34 100644
--- a/plugins/genpass/genpass.plugin.zsh
+++ b/plugins/genpass/genpass.plugin.zsh
@@ -73,8 +73,19 @@ genpass-monkey() {
genpass-xkcd() {
# Generates a 128-bit XKCD-style passphrase
- # EG, 9-mien-flood-Patti-buxom-dozes-ickier-pay-ailed-Foster
+ # e.g, 9-mien-flood-Patti-buxom-dozes-ickier-pay-ailed-Foster
# Can take a numerical argument for generating extra passwords
+
+ if (( ! $+commands[shuf] )); then
+ echo >&2 "$0: \`shuf\` command not found. Install coreutils (\`brew install coreutils\` on macOS)."
+ return 1
+ fi
+
+ if [[ ! -e /usr/share/dict/words ]]; then
+ echo >&2 "$0: no wordlist found in \`/usr/share/dict/words\`. Install one first."
+ return 1
+ fi
+
local -i i num
[[ $1 =~ '^[0-9]+$' ]] && num=$1 || num=1
@@ -90,6 +101,6 @@ genpass-xkcd() {
for i in {1..$num}; do
printf "$n-"
- printf "$dict" | shuf -n "$n" | paste -sd '-'
+ printf "$dict" | shuf -n "$n" | paste -sd '-' -
done
}