I sent this path the 17 of June with exactly that.

I have added the "--edit" option to generate.

Regards
Adrian

El sáb., 16 jul. 2016 a las 10:33, Brian Candler (<[email protected]>)
escribió:

> On 16/07/2016 09:23, Jonas Kalderstam wrote:
> > Here's a script I use all the time.
>
> Yeah, but it would be nice not to script it :-)
>
> To create password foo/bar with metadata, I frequently find myself doing
> "pass edit foo/bar" in one window, and "dd if=/dev/urandom bs=1 count=12
> | base64" in another, then pasting that in.
>
> An option which combines "pass generate" with "pass edit" would be great.
>
> Currently, "pass edit" works with new or exisiting files, but doesn't
> generate a password. "pass generate" by itself generates the password,
> but doesn't open the editor to allow you to add metadata.
> _______________________________________________
> Password-Store mailing list
> [email protected]
> http://lists.zx2c4.com/mailman/listinfo/password-store
>
From 402d63c9ed2fdcf5f778f9b2ff1f181652cbba63 Mon Sep 17 00:00:00 2001
From: Adrian Lopez <[email protected]>
Date: Fri, 17 Jun 2016 13:40:17 +0200
Subject: [PATCH] New option -e|--edit for generate

This option open the editor after the password has been generated
and inserted.
---
 man/pass.1                          |  3 ++-
 src/completion/pass.bash-completion |  2 +-
 src/completion/pass.fish-completion |  1 +
 src/completion/pass.zsh-completion  |  4 +++-
 src/password-store.sh               | 13 +++++++++----
 tests/t0010-generate-tests.sh       |  9 +++++++++
 6 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/man/pass.1 b/man/pass.1
index 33b6036..d1cbb58 100644
--- a/man/pass.1
+++ b/man/pass.1
@@ -111,7 +111,7 @@ ensure that temporary files are created in \fI/dev/shm\fP in order to avoid writ
 difficult-to-erase disk sectors. If \fI/dev/shm\fP is not accessible, fallback to
 the ordinary \fITMPDIR\fP location, and print a warning.
 .TP
-\fBgenerate\fP [ \fI--no-symbols\fP, \fI-n\fP ] [ \fI--clip\fP, \fI-c\fP ] [ \fI--in-place\fP, \fI-i\fP | \fI--force\fP, \fI-f\fP ] \fIpass-name [pass-length]\fP
+\fBgenerate\fP [ \fI--no-symbols\fP, \fI-n\fP ] [ \fI--clip\fP, \fI-c\fP ] [ \fI--in-place\fP, \fI-i\fP | \fI--force\fP, \fI-f\fP | \fI--edit\fP, \fI-e\fP ] \fIpass-name [pass-length]\fP
 Generate a new password using
 .BR pwgen (1)
 of length \fIpass-length\fP (or \fIPASSWORD_STORE_GENERATED_LENGTH\fP if unspecified)
@@ -125,6 +125,7 @@ Prompt before overwriting an existing password,
 unless \fI--force\fP or \fI-f\fP is specified. If \fI--in-place\fP or \fI-i\fP is
 specified, do not interactively prompt, and only replace the first line of the password
 file with the new generated password, keeping the remainder of the file intact.
+With \fI--edit\fP or \fI-e\fP open file in editor after generating the password.
 .TP
 \fBrm\fP [ \fI--recursive\fP, \fI-r\fP ] [ \fI--force\fP, \fI-f\fP ] \fIpass-name\fP
 Remove the password named \fIpass-name\fP from the password store. This command is
diff --git a/src/completion/pass.bash-completion b/src/completion/pass.bash-completion
index 456485b..3811d30 100644
--- a/src/completion/pass.bash-completion
+++ b/src/completion/pass.bash-completion
@@ -106,7 +106,7 @@ _pass()
 				_pass_complete_entries
 				;;
 			generate)
-				COMPREPLY+=($(compgen -W "-n --no-symbols -c --clip -f --force -i --in-place" -- ${cur}))
+				COMPREPLY+=($(compgen -W "-n --no-symbols -c --clip -f --force -i --in-place -e --edit" -- ${cur}))
 				_pass_complete_entries
 				;;
 			cp|copy|mv|rename)
diff --git a/src/completion/pass.fish-completion b/src/completion/pass.fish-completion
index c32a42c..f2bb04f 100644
--- a/src/completion/pass.fish-completion
+++ b/src/completion/pass.fish-completion
@@ -78,6 +78,7 @@ complete -c $PROG -f -A -n '__fish_pass_uses_command generate' -s n -l no-symbol
 complete -c $PROG -f -A -n '__fish_pass_uses_command generate' -s c -l clip -d 'Put the password in clipboard'
 complete -c $PROG -f -A -n '__fish_pass_uses_command generate' -s f -l force -d 'Do not prompt before overwritting'
 complete -c $PROG -f -A -n '__fish_pass_uses_command generate' -s i -l in-place -d 'Replace only the first line with the generated password'
+complete -c $PROG -f -A -n '__fish_pass_uses_command generate' -s e -l edit -d 'Open editor after generating the password'
 complete -c $PROG -f -A -n '__fish_pass_uses_command generate' -a "(__fish_pass_print_entry_dirs)"
 
 complete -c $PROG -f -A -n '__fish_pass_needs_command' -a mv -d 'Command: rename existing password'
diff --git a/src/completion/pass.zsh-completion b/src/completion/pass.zsh-completion
index 27ce15a..23aed7e 100644
--- a/src/completion/pass.zsh-completion
+++ b/src/completion/pass.zsh-completion
@@ -55,7 +55,9 @@ _pass () {
 					"-f[force overwrite]" \
 					"--force[force overwrite]" \
 					"-i[replace first line]" \
-					"--in-place[replace first line]"
+					"--in-place[replace first line]" \
+					"-e[open editor]" \
+					"--edit[open editor]"
 				_pass_complete_entries_with_subdirs
 				;;
 			cp|copy|mv|rename)
diff --git a/src/password-store.sh b/src/password-store.sh
index 63be840..ba55648 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -235,11 +235,12 @@ 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 | --edit,-e] pass-name [pass-length]
 	        Generate a new password of pass-length (or $GENERATED_LENGTH if unspecified) with optionally no symbols.
 	        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.
+	        Edit the new entry.
 	    $PROGRAM rm [--recursive,-r] [--force,-f] pass-name
 	        Remove existing password or directory, optionally forcefully.
 	    $PROGRAM mv [--force,-f] old-path new-path
@@ -431,8 +432,8 @@ cmd_edit() {
 }
 
 cmd_generate() {
-	local opts clip=0 force=0 symbols="-y" inplace=0
-	opts="$($GETOPT -o ncif -l no-symbols,clip,in-place,force -n "$PROGRAM" -- "$@")"
+	local opts clip=0 force=0 symbols="-y" inplace=0 edit=0
+	opts="$($GETOPT -o ncife -l no-symbols,clip,in-place,force,edit -n "$PROGRAM" -- "$@")"
 	local err=$?
 	eval set -- "$opts"
 	while true; do case $1 in
@@ -440,10 +441,11 @@ cmd_generate() {
 		-c|--clip) clip=1; shift ;;
 		-f|--force) force=1; shift ;;
 		-i|--in-place) inplace=1; shift ;;
+    -e|--edit) edit=1; shift ;;
 		--) shift; break ;;
 	esac done
 
-	[[ $err -ne 0 || ( $# -ne 2 && $# -ne 1 ) || ( $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 2 && $# -ne 1 ) || ( $force -eq 1 && $inplace -eq 1 ) ]] && die "Usage: $PROGRAM $COMMAND [--no-symbols,-n] [--clip,-c] [--in-place,-i | --force,-f | --edit,-e] pass-name [pass-length]"
 	local path="$1"
 	local length="${2:-$GENERATED_LENGTH}"
 	check_sneaky_paths "$path"
@@ -476,6 +478,9 @@ cmd_generate() {
 	else
 		clip "$pass" "$path"
 	fi
+	if [[ $edit -eq 1 ]]; then
+		cmd_edit $path
+	fi
 }
 
 cmd_delete() {
diff --git a/tests/t0010-generate-tests.sh b/tests/t0010-generate-tests.sh
index cadb76f..0dc8505 100755
--- a/tests/t0010-generate-tests.sh
+++ b/tests/t0010-generate-tests.sh
@@ -16,4 +16,13 @@ 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" command with --edit flag' '
+        "$PASS" init $KEY1
+        export FAKE_EDITOR_PASSWORD="big fat fake password" &&
+        export PATH="$TEST_HOME:$PATH"
+        export EDITOR="fake-editor-change-password.sh" &&
+        "$PASS" generate -e cred3 90 &&
+        [[ $("$PASS" show cred3) == "$FAKE_EDITOR_PASSWORD" ]]
+'
+
 test_done
-- 
2.8.0

_______________________________________________
Password-Store mailing list
[email protected]
http://lists.zx2c4.com/mailman/listinfo/password-store

Reply via email to