[PATCH] Add option --flat

koelblandreas at freenet.de koelblandreas at freenet.de
Tue May 24 18:35:07 UTC 2022


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

Support an computable way to find passwords. This avoids the use of
additional tools.

By adding the flag --flat after pass find it prints the path of found
passwords without colors, indentions or special characters.
---
 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..6c90f19 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 -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' | sed -E 's/└──(.*)/\1/' | tr '\n' '/' | tr -d ' ' | rev | cut -c2- | rev | xargs echo | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" | sed "s/\x0f//g"
+    fi
 }
 
 cmd_grep() {
-- 
2.35.1



More information about the Password-Store mailing list