Oh, alright, thanks Kjetil. Here's an updated patch with a shorter
config variable name:

commit 1609822d4187dd353be404f9f184879906f2d1e5
Author: Nathan Wallace <[email protected]>
Date:   Thu Dec 17 23:48:08 2015 -0500

    generate: default length to 15 if not specified
    
    When generating passwords, users probably have a preferred password
    length. Specifying the length every time a user generates a
password is
    repetitive and unnecessary.
    
    The default length is 15 characters, but can be configured by the
user
    with the PASSWORD_STORE_LENGTH environment variable, or overridden
by
    providing the length when running the generate command as before.

diff --git a/src/password-store.sh b/src/password-store.sh
index d535a74..7edb695 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -15,6 +15,7 @@ which gpg2 &>/dev/null && GPG="gpg2"
 PREFIX="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
 X_SELECTION="${PASSWORD_STORE_X_SELECTION:-clipboard}"
 CLIP_TIME="${PASSWORD_STORE_CLIP_TIME:-45}"
+DEFAULT_LENGTH="${PASSWORD_STORE_LENGTH:-15}"
 
 export GIT_DIR="${PASSWORD_STORE_GIT:-$PREFIX}/.git"
 export GIT_WORK_TREE="${PASSWORD_STORE_GIT:-$PREFIX}"
@@ -234,8 +235,9 @@ cmd_usage() {
                overwriting existing password unless forced.
            $PROGRAM edit pass-name
                Insert a new password or edit an existing password
using ${EDITOR:-vi}.
-           $PROGRAM generate [--no-symbols,-n] [--clip,-c] [--in-
place,-i | --force,-f] pass-name pass-length
+           $PROGRAM generate [--no-symbols,-n] [--clip,-c] [--in-
place,-i | --force,-f] pass-name [pass-length]
                Generate a new password of pass-length with optionally
no symbols.
+               If pass-length is not specified, the password will be
$DEFAULT_LENGTH characters long.
                Optionally put it on the clipboard and clear board
after $CLIP_TIME seconds.
                Prompt before overwriting existing password unless
forced.
                Optionally replace only the first line of an existing
file with a new password.
@@ -441,9 +443,10 @@ cmd_generate() {
                --) shift; break ;;
        esac done
 
-       [[ $err -ne 0 || $# -ne 2 || ( $force -eq 1 && $inplace -eq 1
) ]] && die "Usage: $PROGRAM $COMMAND [--no-symbols,-n] [--clip,-c] [
--in-place,-i | --force,-f] pass-name pass-length"
+       [[ $err -ne 0 || ( $# -ne 1 && $# -ne 2 ) || ( $force -eq 1 &&
$inplace -eq 1 ) ]] &&
+               die "Usage: $PROGRAM $COMMAND [--no-symbols,-n] [
--clip,-c] [--in-place,-i | --force,-f] pass-name [pass-length]"
        local path="$1"
-       local length="$2"
+       local length="${2:-$DEFAULT_LENGTH}"
        check_sneaky_paths "$path"
        [[ ! $length =~ ^[0-9]+$ ]] && die "Error: pass-length
\"$length\" must be a number."
        mkdir -p -v "$PREFIX/$(dirname "$path")"
diff --git a/tests/t0010-generate-tests.sh b/tests/t0010-generate-
tests.sh
index cadb76f..5212f8d 100755
--- a/tests/t0010-generate-tests.sh
+++ b/tests/t0010-generate-tests.sh
@@ -16,4 +16,10 @@ test_expect_success 'Test replacement of first line'
'
        [[ $("$PASS" show cred2) == "$(printf "This is a fake
password\\npassword\\nwith\\nmany\\nlines\\nin it bla bla")" ]]
 '
 
+test_expect_success 'Test "generate" default length' '
+       "$PASS" init $KEY1 &&
+       "$PASS" generate cred3 &&
+       [[ $("$PASS" show cred3 | wc -m) -eq 16 ]]
+'
+
 test_done

On Sun, 2015-12-20 at 02:09 +0100, Kjetil Torgrim Homme wrote:
> On 2015-12-18 19:41, Nathan Wallace wrote:
> > Great, thanks Kevin.  My reasons for including the environment
> > variable configuration probably had to do with the fact that I
> > chose 15 characters as the default pretty arbitrarily.  It seems
> > long enough to me, but maybe some folks with more security needs
> > might want it to default to 20, for example.  I wasn't sure exactly
> > what the best default length would be, so that's partly why I
> > included the override.  But I think you make a good point about
> > just overriding it on the command line, so I'll defer to you all!
> 
> I think you misunderstood Kevin.  he was bikeshedding the name of the
> environment variable, not its existence.  and I agree,
> "PASSWORD_STORE_LENGTH" is a fine name,
> "PASSWORD_STORE_DEFAULT_LENGTH" is needlessly cumbersome.
> 
> (btw, I typically use 12, or 16 without symbols.  15 seems a
> reasonable default for me.)
> 
_______________________________________________
Password-Store mailing list
[email protected]
http://lists.zx2c4.com/mailman/listinfo/password-store

Reply via email to