Added type for pwgen

This commit is contained in:
斟酌 鵬兄 2025-05-20 04:24:17 +08:00
parent 33a411b203
commit b0e98bad0a

View File

@ -19,14 +19,21 @@ function kres {
} }
function pwgen { function pwgen {
local _LEN=$1 local _LEN=$1 _TYPE=$2
case $_LEN in case $_LEN in
''|*[!0-9]*) *[!0-9]*)
echo "Enter a valid number" > /dev/stderr echo "Enter a valid number" > /dev/stderr
return 1 return 1
;; ;;
'')
echo "Usage: pwgen [LEN] [TYPE]"
return 1
;;
esac esac
LC_ALL=C tr -dc '[:graph:]' </dev/urandom | head -c $_LEN if [ -z "$_TYPE" ]; then
_TYPE="graph"
fi
LC_ALL=C tr -dc "[:$_TYPE:]" </dev/urandom | head -c $_LEN
if [ -t 1 ]; then if [ -t 1 ]; then
echo echo
fi fi