[pass] [PATCH] add field option to the show command.

jvenant jvenant at invicem.pro
Wed Mar 26 09:46:26 CET 2014


 Add the capacity to output or copy in the clipboard only
 the specified field instead of the password.
 Using the standard format : <field>: <value> in the password data
---
 src/password-store.sh | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/password-store.sh b/src/password-store.sh
index c576844..05ff927 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -230,12 +230,14 @@ case "$command" in
 		;;
 	show|ls|list)
 		clip=0
+		field=""
 
-		opts="$($GETOPT -o c -l clip -n "$program" -- "$@")"
+		opts="$($GETOPT -o cf: -l clip,field -n "$program" -- "$@")"
 		err=$?
 		eval set -- "$opts"
 		while true; do case $1 in
 			-c|--clip) clip=1; shift ;;
+			-f|--field) field="$2"; shift 2 ;;
 			--) shift; break ;;
 		esac done
 
@@ -248,11 +250,20 @@ case "$command" in
 		passfile="$PREFIX/$path.gpg"
 		if [[ -f $passfile ]]; then
 			if [[ $clip -eq 0 ]]; then
-				exec $GPG -d $GPG_OPTS "$passfile"
+
+				if [[ -n $field ]]; then
+					exec $GPG -d $GPG_OPTS "$passfile" | sed -n "/^$field: / s/$field: //p"
+				else
+					exec $GPG -d $GPG_OPTS "$passfile"
+				fi
 			else
-				pass="$($GPG -d $GPG_OPTS "$passfile" | head -n 1)"
-				[[ -n $pass ]] || exit 1
-				clip "$pass" "$path"
+				if [[ -n $field ]]; then
+					field="$($GPG -d $GPG_OPTS "$passfile" | sed -n "/^$field: / s/$field: //p")"
+				else
+					field="$($GPG -d $GPG_OPTS "$passfile" | head -n 1)"
+				fi
+				[[ -n $field ]] || exit 1
+				clip "$field" "$path"
 			fi
 		elif [[ -d $PREFIX/$path ]]; then
 			if [[ -z $path ]]; then
-- 
1.9.1



More information about the Password-Store mailing list