Clean up pw()

This commit is contained in:
Eryn Wells 2013-08-09 18:21:34 -07:00
parent e9901e62b7
commit 5882ad7d0a

View file

@ -1,6 +1,34 @@
#!/bin/zsh #!/bin/zsh
# vim:ft=zsh # vim:ft=zsh
function _usage_pw
{
cat <<EOF
Usage: $1 [-c <num>] [-h] [-l <num>] [-s <set>]
Password generator. Uses the system random data generator to produce passwords
of the provided length.
Arguments:
-c Count. Number of passwords to generate. (default: 1)
-h Help. This message.
-l Length. Number of characters per password. (default: 16)
-s Character set. Set of characters from which each character of a
password is generated. (default: all)
alpha Uppercase and lowercase ASCII characters (A-Za-z)
num Numeric characters (0-9)
alnum The above two sets combined
sym Symbol set, including: ! @ # $ % ^ & *
xsym Extended symbols. Above plus . ; : - + =
all Alphanumeric and symbol sets above
xall Alphanumeric and extended symbol sets above
EOF
}
function pw
{
local ALPHA_SET='A-Za-z' local ALPHA_SET='A-Za-z'
local NUMERIC_SET='0-9' local NUMERIC_SET='0-9'
local SYM_SET='!@#$%^&*' local SYM_SET='!@#$%^&*'
@ -12,9 +40,10 @@ local XALL_SET="${ALNUM_SET}${XSYM_SET}"
local -i length=16 count=1 local -i length=16 count=1
local charset="$ALL_SET" local charset="$ALL_SET"
while getopts 'c:l:s:' opt; do while getopts 'c:hl:s:' opt; do
case $opt in case $opt in
c) count=$OPTARG;; c) count=$OPTARG;;
h) _usage_pw $0; return 0;;
l) length=$OPTARG;; l) length=$OPTARG;;
s) case $OPTARG in s) case $OPTARG in
alpha) charset="$ALPHA_SET";; alpha) charset="$ALPHA_SET";;
@ -42,3 +71,6 @@ if [[ $SYS == 'darwin' ]]; then
fi fi
eval "$cmd" eval "$cmd"
}
pw $@