Hi,

This is my first time sending in a patch through mail (I'm more used to
pull-requests) so I hope I don't mess up anything.

I made two changes:

When a user wants to access extra information stored in a pass file by
using the line-number argument, it at least implies they're not
accessing a password. The previous text assumed they do.
The text now also reflects the different output possibilities.

and

Added a '--line', '-l' option to the show command to allow the user
to access extra information stored using '--multiline', '-m'.
This way they don't have to print out the password alongside the
needed information or place the needed line onto the clipboard first.
Added information about the option in the manpage.
Added a test for this option to the show tests. (test passes)


Hope they are of some use!

Ruven Salamon.

From 51daa56113c65111c5d8cbe8e3bedfd72292494f Mon Sep 17 00:00:00 2001
From: Ruven Salamon <[email protected]>
Date: Fri, 10 Aug 2018 02:56:06 +0200
Subject: [PATCH 1/2] Changed line number error message

When a user wants to access extra information stored in a pass file by
using the line-number argument, it at least implies they're not
accessing a password. The previous text assumed they do.
The text now also reflects the different output possibilities.
---
 src/password-store.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/password-store.sh b/src/password-store.sh
index 7264ffc..81a1e78 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -369,10 +369,12 @@ cmd_show() {
 		else
 			[[ $selected_line =~ ^[0-9]+$ ]] || die "Clip location '$selected_line' is not a number."
 			pass="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | tail -n +${selected_line} | head -n 1)" || exit $?
-			[[ -n $pass ]] || die "There is no password to put on the clipboard at line ${selected_line}."
+
 			if [[ $clip -eq 1 ]]; then
+				[[ -n $pass ]] || die "There is nothing to put on the clipboard at line ${selected_line}."
 				clip "$pass" "$path"
 			elif [[ $qrcode -eq 1 ]]; then
+				[[ -n $pass ]] || die "There is nothing to put into a qr code at line ${selected_line}."
 				qrcode "$pass" "$path"
 			fi
 		fi
-- 
2.18.0

From 57a83792ebd001d16e72a1de488c5d73a1c0dc13 Mon Sep 17 00:00:00 2001
From: Ruven Salamon <[email protected]>
Date: Fri, 10 Aug 2018 03:00:43 +0200
Subject: [PATCH 2/2] Added line option to show

Added a '--line', '-l' option to the show command to allow the user
to access extra information stored using '--multiline', '-m'.
This way they don't have to print out the password alongside the
needed information or place the needed line onto the clipboard first.
Added information about the option in the manpage.
Added a test for this option to the show tests. (test passes)
---
 man/pass.1                |  4 ++--
 src/password-store.sh     | 13 +++++++++----
 tests/t0020-show-tests.sh |  5 +++++
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/man/pass.1 b/man/pass.1
index 01a3fbe..1173303 100644
--- a/man/pass.1
+++ b/man/pass.1
@@ -94,7 +94,7 @@ List names of passwords inside the tree that match \fIpass-names\fP by using the
 .BR tree (1)
 program. This command is alternatively named \fBsearch\fP.
 .TP
-\fBshow\fP [ \fI--clip\fP[=\fIline-number\fP], \fI-c\fP[\fIline-number\fP] ] [ \fI--qrcode\fP[=\fIline-number\fP], \fI-q\fP[\fIline-number\fP] ] \fIpass-name\fP
+\fBshow\fP [ \fI--clip\fP[=\fIline-number\fP], \fI-c\fP[\fIline-number\fP] ] [ \fI--qrcode\fP[=\fIline-number\fP], \fI-q\fP[\fIline-number\fP] ], [\fI--line\fP=\fIline-number\fP, \fI-e\fP \fIline-number\fP] \fIpass-name\fP
 Decrypt and print a password named \fIpass-name\fP. If \fI--clip\fP or \fI-c\fP
 is specified, do not print the password but instead copy the first (or otherwise specified)
 line to the clipboard using
@@ -102,7 +102,7 @@ line to the clipboard using
 and then restore the clipboard after 45 (or \fIPASSWORD_STORE_CLIP_TIME\fP) seconds. If \fI--qrcode\fP
 or \fI-q\fP is specified, do not print the password but instead display a QR code using
 .BR qrencode (1)
-either to the terminal or graphically if supported.
+either to the terminal or graphically if supported. If \fI--line\fP or \fI-l\fP is specified, print the line at \fIline-number\fP to the standard output.
 .TP
 \fBinsert\fP [ \fI--echo\fP, \fI-e\fP | \fI--multiline\fP, \fI-m\fP ] [ \fI--force\fP, \fI-f\fP ] \fIpass-name\fP
 Insert a new password into the password store called \fIpass-name\fP. This will
diff --git a/src/password-store.sh b/src/password-store.sh
index 81a1e78..455de58 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -346,24 +346,26 @@ cmd_init() {
 }
 
 cmd_show() {
-	local opts selected_line clip=0 qrcode=0
-	opts="$($GETOPT -o q::c:: -l qrcode::,clip:: -n "$PROGRAM" -- "$@")"
+	local opts selected_line clip=0 qrcode=0 line=0
+	opts="$($GETOPT -o q::c::l:: -l qrcode::,clip::,line:: -n "$PROGRAM" -- "$@")"
 	local err=$?
 	eval set -- "$opts"
 	while true; do case $1 in
 		-q|--qrcode) qrcode=1; selected_line="${2:-1}"; shift 2 ;;
 		-c|--clip) clip=1; selected_line="${2:-1}"; shift 2 ;;
+		-l|--line) line=1; selected_line="${2:-1}"; shift 2 ;;
 		--) shift; break ;;
 	esac done
 
-	[[ $err -ne 0 || ( $qrcode -eq 1 && $clip -eq 1 ) ]] && die "Usage: $PROGRAM $COMMAND [--clip[=line-number],-c[line-number]] [--qrcode[=line-number],-q[line-number]] [pass-name]"
+	[[ $err -ne 0 || ( $qrcode -eq 1 && $clip -eq 1 ) || ( $qrcode -eq 1 && $line -eq 1 ) || ( $clip -eq 1 && $line -eq 1)]] && \
+		die "Usage: $PROGRAM $COMMAND [--clip[=line-number],-c[line-number]] [--qrcode[=line-number],-q[line-number]] [pass-name]"
 
 	local pass
 	local path="$1"
 	local passfile="$PREFIX/$path.gpg"
 	check_sneaky_paths "$path"
 	if [[ -f $passfile ]]; then
-		if [[ $clip -eq 0 && $qrcode -eq 0 ]]; then
+		if [[ $clip -eq 0 && $qrcode -eq 0 && $line -eq 0 ]]; then
 			pass="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | $BASE64)" || exit $?
 			echo "$pass" | $BASE64 -d
 		else
@@ -376,6 +378,9 @@ cmd_show() {
 			elif [[ $qrcode -eq 1 ]]; then
 				[[ -n $pass ]] || die "There is nothing to put into a qr code at line ${selected_line}."
 				qrcode "$pass" "$path"
+			elif [[ $line -eq 1 ]]; then
+				[[ -n $pass ]] || die "There is nothing to print out at line ${selected_line}."
+				echo "$pass"
 			fi
 		fi
 	elif [[ -d $PREFIX/$path ]]; then
diff --git a/tests/t0020-show-tests.sh b/tests/t0020-show-tests.sh
index a4b782f..4a5e679 100755
--- a/tests/t0020-show-tests.sh
+++ b/tests/t0020-show-tests.sh
@@ -19,4 +19,9 @@ test_expect_success 'Test "show" of nonexistant password' '
 	test_must_fail "$PASS" show cred2
 '
 
+test_expect_success 'Test "show" --line/-e option' '
+	echo -e "BLAH!!\nSOMEINFO!!" | "$PASS" insert -m cred3 &&
+	[[ $("$PASS" show -l2 cred3) == "SOMEINFO!!" ]]
+'
+
 test_done
-- 
2.18.0

Attachment: signature.asc
Description: OpenPGP digital signature

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

Reply via email to