<p dir="ltr">I think this is a great idea and the code looks good at a quick glance. A small bikeshed comment is that I don't think that default is required in the environment variable because it is probably expected that the command line argument will override. So 'PASSWORD_STORE_LENGTH' would be sufficient IMHO. </p>
<div class="gmail_quote">On Dec 18, 2015 12:18 AM, "Nathan Wallace" <<a href="mailto:nathan@nosuchthingastwo.com">nathan@nosuchthingastwo.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">---<br>
src/password-store.sh | 9 ++++++---<br>
tests/t0010-generate-tests.sh | 6 ++++++<br>
2 files changed, 12 insertions(+), 3 deletions(-)<br>
<br>
diff --git a/src/password-store.sh b/src/password-store.sh<br>
index d535a74..ad6d367 100755<br>
--- a/src/password-store.sh<br>
+++ b/src/password-store.sh<br>
@@ -15,6 +15,7 @@ which gpg2 &>/dev/null && GPG="gpg2"<br>
PREFIX="${PASSWORD_STORE_DIR:-$HOME/.password-store}"<br>
X_SELECTION="${PASSWORD_STORE_X_SELECTION:-clipboard}"<br>
CLIP_TIME="${PASSWORD_STORE_CLIP_TIME:-45}"<br>
+DEFAULT_LENGTH="${PASSWORD_STORE_DEFAULT_LENGTH:-15}"<br>
<br>
export GIT_DIR="${PASSWORD_STORE_GIT:-$PREFIX}/.git"<br>
export GIT_WORK_TREE="${PASSWORD_STORE_GIT:-$PREFIX}"<br>
@@ -234,8 +235,9 @@ cmd_usage() {<br>
overwriting existing password unless forced.<br>
$PROGRAM edit pass-name<br>
Insert a new password or edit an existing password using ${EDITOR:-vi}.<br>
- $PROGRAM generate [--no-symbols,-n] [--clip,-c] [--in-place,-i | --force,-f] pass-name pass-length<br>
+ $PROGRAM generate [--no-symbols,-n] [--clip,-c] [--in-place,-i | --force,-f] pass-name [pass-length]<br>
Generate a new password of pass-length with optionally no symbols.<br>
+ If pass-length is not specified, the password will be $DEFAULT_LENGTH characters long.<br>
Optionally put it on the clipboard and clear board after $CLIP_TIME seconds.<br>
Prompt before overwriting existing password unless forced.<br>
Optionally replace only the first line of an existing file with a new password.<br>
@@ -441,9 +443,10 @@ cmd_generate() {<br>
--) shift; break ;;<br>
esac done<br>
<br>
- [[ $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"<br>
+ [[ $err -ne 0 || ( $# -ne 1 && $# -ne 2 ) || ( $force -eq 1 && $inplace -eq 1 ) ]] &&<br>
+ die "Usage: $PROGRAM $COMMAND [--no-symbols,-n] [--clip,-c] [--in-place,-i | --force,-f] pass-name [pass-length]"<br>
local path="$1"<br>
- local length="$2"<br>
+ local length="${2:-$DEFAULT_LENGTH}"<br>
check_sneaky_paths "$path"<br>
[[ ! $length =~ ^[0-9]+$ ]] && die "Error: pass-length \"$length\" must be a number."<br>
mkdir -p -v "$PREFIX/$(dirname "$path")"<br>
diff --git a/tests/t0010-generate-tests.sh b/tests/t0010-generate-tests.sh<br>
index cadb76f..5212f8d 100755<br>
--- a/tests/t0010-generate-tests.sh<br>
+++ b/tests/t0010-generate-tests.sh<br>
@@ -16,4 +16,10 @@ test_expect_success 'Test replacement of first line' '<br>
[[ $("$PASS" show cred2) == "$(printf "This is a fake password\\npassword\\nwith\\nmany\\nlines\\nin it bla bla")" ]]<br>
'<br>
<br>
+test_expect_success 'Test "generate" default length' '<br>
+ "$PASS" init $KEY1 &&<br>
+ "$PASS" generate cred3 &&<br>
+ [[ $("$PASS" show cred3 | wc -m) -eq 16 ]]<br>
+'<br>
+<br>
test_done<br>
--<br>
2.5.0<br>
<br>
_______________________________________________<br>
Password-Store mailing list<br>
<a href="mailto:Password-Store@lists.zx2c4.com">Password-Store@lists.zx2c4.com</a><br>
<a href="http://lists.zx2c4.com/mailman/listinfo/password-store" rel="noreferrer" target="_blank">http://lists.zx2c4.com/mailman/listinfo/password-store</a><br>
</blockquote></div>