[PATCH] Add option --flat

koelblandreas at freenet.de koelblandreas at freenet.de
Sat May 28 05:20:50 UTC 2022


From: Andreas Kölbl <koelblandreas at freenet.de>

Support a computable way to find passwords. Avoid the use of
additional tools.

By adding the flag --flat after "pass find" it prints paths of found
passwords without colors or indentions.
---
 src/password-store.sh | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/password-store.sh b/src/password-store.sh
index 22e818f..ab41ba4 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -282,8 +282,8 @@ cmd_usage() {
 	        Selectively reencrypt existing passwords using new gpg-id.
 	    $PROGRAM [ls] [subfolder]
 	        List passwords.
-	    $PROGRAM find pass-names...
-	    	List passwords that match pass-names.
+	    $PROGRAM find [--flat] pass-names...
+		    List passwords that match pass-names and optionally print it without colors, indentions or special characters.
 	    $PROGRAM [show] [--clip[=line-number],-c[line-number]] pass-name
 	        Show existing password and optionally put it on the clipboard.
 	        If put on the clipboard, it will be cleared in $CLIP_TIME seconds.
@@ -412,9 +412,18 @@ cmd_show() {
 
 cmd_find() {
 	[[ $# -eq 0 ]] && die "Usage: $PROGRAM $COMMAND pass-names..."
-	IFS="," eval 'echo "Search Terms: $*"'
+    local opts flat="0"
+	case $1 in
+		-f|--flat) flat=1; shift ;;
+		--) shift; break ;;
+    esac
 	local terms="*$(printf '%s*|*' "$@")"
-	tree -N -C -l --noreport -P "${terms%|*}" --prune --matchdirs --ignore-case "$PREFIX" 3>&- | tail -n +2 | sed -E 's/\.gpg(\x1B\[[0-9]+m)?( ->|$)/\1\2/g'
+    if [ $flat -eq 0 ]; then
+        IFS="," eval 'echo "Search Terms: $*"'
+        tree -N -C -l --noreport -P "${terms%|*}" --prune --matchdirs --ignore-case "$PREFIX" 3>&- | tail -n +2 | sed -E 's/\.gpg(\x1B\[[0-9]+m)?( ->|$)/\1\2/g'
+    else
+        tree -f -N -l --noreport -P "${terms%|*}" --prune --matchdirs --ignore-case "$PREFIX" 3>&- | tail -n +2 | sed -E '/\.gpg/!d' | sed -E 's/└[─]*//g' | sed -E 's/[─]*//g' | sed -E 's/│[ ]*//g' | sed -E 's/├//g' | sed -E "s|${PREFIX}/||g"| sed -E 's/\.gpg//g' | tr -d ' '
+    fi
 }
 
 cmd_grep() {
-- 
2.35.1



More information about the Password-Store mailing list