Hello everyone, 

For a project of mine[1] I need to script `pass`. I am aware of the last 
thread[2] about that topic from half a year ago, but my patch is much smaller 
in size and features.     


It simply adds a parameter --parsable (-p) to `pass ls` to display the string 
`pass show` expects. 


Please let me know if this can be merged into the master repository. 


A patch is included as an attachment, and feel free to pull from [3]. 


Tobias




[1] https://hackaday.io/project/9564/
[2] https://lists.zx2c4.com/pipermail/password-store/2016-February/001965.html
[3] https://github.com/girst/password-store
diff --git a/src/password-store.sh b/src/password-store.sh
index 63be840..06f4631 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -220,8 +220,8 @@ cmd_usage() {
 	    $PROGRAM init [--path=subfolder,-p subfolder] gpg-id...
 	        Initialize new password storage and use gpg-id for encryption.
 	        Selectively reencrypt existing passwords using new gpg-id.
-	    $PROGRAM [ls] [subfolder]
-	        List passwords.
+	    $PROGRAM [ls] [--parseable,-p] [subfolder]
+	        List passwords. Optionally, print machine readable output (for feeding back into pass).
 	    $PROGRAM find pass-names...
 	    	List passwords that match pass-names.
 	    $PROGRAM [show] [--clip[=line-number],-c[line-number]] pass-name
@@ -295,12 +295,13 @@ cmd_init() {
 }
 
 cmd_show() {
-	local opts clip_location clip=0
-	opts="$($GETOPT -o c:: -l clip:: -n "$PROGRAM" -- "$@")"
+	local opts clip_location clip=0 parsable=0
+	opts="$($GETOPT -o c::p -l clip::,parsable -n "$PROGRAM" -- "$@")"
 	local err=$?
 	eval set -- "$opts"
 	while true; do case $1 in
 		-c|--clip) clip=1; clip_location="${2:-1}"; shift 2 ;;
+		-p|--parsable) parsable=1; shift;;
 		--) shift; break ;;
 	esac done
 
@@ -319,12 +320,16 @@ cmd_show() {
 			clip "$pass" "$path"
 		fi
 	elif [[ -d $PREFIX/$path ]]; then
-		if [[ -z $path ]]; then
-			echo "Password Store"
+		if [[ $parsable -eq 0 ]]; then
+			if [[ -z $path ]]; then
+				echo "Password Store"
+			else
+				echo "${path%\/}"
+			fi
+			tree -C -l --noreport "$PREFIX/$path" | tail -n +2 | sed -E 's/\.gpg(\x1B\[[0-9]+m)?( ->|$)/\1\2/g' # remove .gpg at end of line, but keep colors
 		else
-			echo "${path%\/}"
+			tree -f -i -l -F --noreport "$PREFIX/$path" | tail -n +2 | grep -v '/$' | sed -E 's/\.gpg(\x1B\[[0-9]+m)?( ->.+|$)//g' | sed "s|$PREFIX/||g"
 		fi
-		tree -C -l --noreport "$PREFIX/$path" | tail -n +2 | sed -E 's/\.gpg(\x1B\[[0-9]+m)?( ->|$)/\1\2/g' # remove .gpg at end of line, but keep colors
 	elif [[ -z $path ]]; then
 		die "Error: password store is empty. Try \"pass init\"."
 	else
_______________________________________________
Password-Store mailing list
[email protected]
http://lists.zx2c4.com/mailman/listinfo/password-store

Reply via email to