On Mon, Mar 10, 2014 at 04:42:07PM +0100, Jason A. Donenfeld wrote:
Here on the mailing list with git-send-email.
---end quoted text---

Will you accept a git-patch?
(Attached.)

This patch:

  - adds -C and --Clip options, like -c and --clip except that the clipboard's 
contents are not restored.

Steve
>From 8c0346bddc3a8147c0d0d5f5f89c001e0ebb01a4 Mon Sep 17 00:00:00 2001
From: Stephen Blott <[email protected]>
Date: Mon, 10 Mar 2014 15:43:15 +0000
Subject: [PATCH] Add -C and --Clip options, no clear clipboard.

---
 man/pass.1            |    3 +++
 src/password-store.sh |   22 ++++++++++++++--------
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/man/pass.1 b/man/pass.1
index efb5d9b..2f0de51 100644
--- a/man/pass.1
+++ b/man/pass.1
@@ -75,6 +75,9 @@ clipboard using
 .BR xclip (1)
 and then restore the clipboard after 45 seconds.
 .TP
+\fBshow\fP \fI--Clip\fP, \fI-C\fP \fIpass-name\fP
+As above, except that the clipboard's contents are not restored.
+.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
 read the new password from standard in. If \fI--echo\fP or \fI-e\fP is \fInot\fP specified,
diff --git a/src/password-store.sh b/src/password-store.sh
index 2500253..b9a1ad5 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -38,6 +38,9 @@ Usage:
     $program [show] [--clip,-c] pass-name
         Show existing password and optionally put it on the clipboard.
         If put on the clipboard, it will be cleared in 45 seconds.
+    $program [show] --Clip,-C pass-name
+        Show existing password and put it on the clipboard.
+        The clipboard will not be cleared automatically.
     $program insert [--echo,-e | --multiline,-m] [--force,-f] pass-name
         Insert new password. Optionally, echo the password back to the console
         during entry. Or, optionally, the entry may be multiline. Prompt before
@@ -193,11 +196,12 @@ case "$command" in
 	show|ls|list)
 		clip=0
 
-		opts="$($GETOPT -o c -l clip -n "$program" -- "$@")"
+		opts="$($GETOPT -o cC -l clip,Clip -n "$program" -- "$@")"
 		err=$?
 		eval set -- "$opts"
 		while true; do case $1 in
 			-c|--clip) clip=1; shift ;;
+			-C|--Clip) clip=2; shift ;;
 			--) shift; break ;;
 		esac done
 
@@ -209,13 +213,15 @@ case "$command" in
 		path="$1"
 		passfile="$PREFIX/$path.gpg"
 		if [[ -f $passfile ]]; then
-			if [[ $clip -eq 0 ]]; then
-				exec gpg2 -d $GPG_OPTS "$passfile"
-			else
-				pass="$(gpg2 -d $GPG_OPTS "$passfile" | head -n 1)"
-				[[ -n $pass ]] || exit 1
-				clip "$pass" "$path"
-			fi
+                        case $clip in
+                                0 ) exec gpg2 -d $GPG_OPTS "$passfile" ;;
+                                2 ) # copy password to clipboard, do not clear
+                                    gpg2 -d $GPG_OPTS "$passfile" | tr -d '\n' | xclip -selection clipboard ;;
+                                1 ) # copy password to clipboard, clear after 45 seconds
+                                    pass="$(gpg2 -d $GPG_OPTS "$passfile" | head -n 1)"
+				    [[ -n $pass ]] || exit 1
+				    clip "$pass" "$path" ;;
+                        esac
 		elif [[ -d $PREFIX/$path ]]; then
 			if [[ -z $path ]]; then
 				echo "Password Store"
-- 
1.7.10.4

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

Reply via email to