]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/genpass/genpass-monkey
initial
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / genpass / genpass-monkey
1 #!/usr/bin/env zsh
2 #
3 # Usage: genpass-monkey [NUM]
4 #
5 # Generate a password made of 26 alphanumeric characters
6 # with the security margin of at least 128 bits.
7 #
8 # Example password: nz5ej2kypkvcw0rn5cvhs6qxtm
9 #
10 # If given a numerical argument, generate that many passwords.
11
12 emulate -L zsh -o no_unset -o warn_create_global -o warn_nested_var
13
14 if [[ ARGC -gt 1 || ${1-1} != ${~:-<1-$((16#7FFFFFFF))>} ]]; then
15   print -ru2 -- "usage: $0 [NUM]"
16   return 1
17 fi
18
19 zmodload zsh/system || return
20
21 {
22   local -r chars=abcdefghjkmnpqrstvwxyz0123456789
23   local c
24   repeat ${1-1}; do
25     repeat 26; do
26       sysread -s1 c || return
27       # There is uniform because $#chars divides 256.
28       print -rn -- $chars[#c%$#chars+1]
29     done
30     print
31   done
32 } </dev/urandom