diff options
author | Dennis Eriksen <d@ennis.no> | 2023-09-07 08:05:49 +0200 |
---|---|---|
committer | Dennis Eriksen <d@ennis.no> | 2023-09-07 08:05:49 +0200 |
commit | e5e626d8adbcd564fd9ece1097446a05075621af (patch) | |
tree | be98568801e709caabe66769ec475c501f9368ea | |
parent | WIP: Cleanup and standardization - Done? (diff) | |
download | makepass-e5e626d8adbcd564fd9ece1097446a05075621af.tar.gz |
use the $MAX variable
-rwxr-xr-x | makepass.zsh | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/makepass.zsh b/makepass.zsh index c513086..558585b 100755 --- a/makepass.zsh +++ b/makepass.zsh @@ -19,7 +19,7 @@ # -g = global # -r = readonly -typeset -gri MAX_LENGTH=255 # max length of passwords +typeset -gri MAX=255 # max length of passwords typeset -gri RANGE_MAX=42 # max length when using random length typeset -gri RANGE_MIN=8 # min length when using random length typeset -gri PASS_WORDS=8 # number of words in passphrases @@ -217,10 +217,10 @@ function main() { h) _makepass_help && return 0;; l) - [[ $OPTARG = <0-255> ]] || die "-l takes a number between 0 and 255" + [[ $OPTARG = <0-> && $OPTARG -le $MAX ]] || die "-l takes a number between 0 and $MAX" LENGTH=$OPTARG;; n) - [[ $OPTARG = <1-255> ]] || die "-n takes a number between 1 and 255" + [[ $OPTARG = <1-> && $OPTARG -le $MAX ]] || die "-n takes a number between 1 and $MAX" NUMBER=$OPTARG;; p) PRINTLEN=1;; @@ -242,8 +242,10 @@ function main() { [[ -n $1 ]] && LENGTH=$1 # Check $LENGTH and $NUMBER - [[ $LENGTH = <0-255> ]] || die "length must be a number between 0 and 255" - [[ $NUMBER = <1-255> ]] || die "number-argument must be between 1 and 255" + # Both are integers so no need to check if they are numbers + # If they were somehow assigned to, say "xx", they would be 0 + (( 0 <= LENGTH && LENGTH <= MAX )) || die "length must be a number between 0 and $MAX" + (( 1 <= NUMBER && NUMBER <= MAX )) || die "number-argument must be between 1 and $MAX" # |