[PATCH v2 1/1] Add --flatten,-f for better interaction with filters.

Dimitri Sabadie hadronized at strongly-typed-thoughts.net
Sun Apr 26 12:07:15 UTC 2026


The current mitigation has always been to use various scripts for every
integration, such as dmenu, bemenu, skim, fzf, etc. and it requires
everyone to keep writing the same code. This commit allows to get an
easy-to-consume interface for all filter programs.
---
 src/password-store.sh | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/password-store.sh b/src/password-store.sh
index 22e818f..b77c67c 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -366,17 +366,18 @@ cmd_init() {
 }
 
 cmd_show() {
-	local opts selected_line clip=0 qrcode=0
-	opts="$($GETOPT -o q::c:: -l qrcode::,clip:: -n "$PROGRAM" -- "$@")"
+	local opts selected_line clip=0 qrcode=0 flatten=0
+	opts="$($GETOPT -o q::c::f:: -l qrcode::,clip::,flatten:: -n "$PROGRAM" -- "$@")"
 	local err=$?
 	eval set -- "$opts"
 	while true; do case $1 in
 		-q|--qrcode) qrcode=1; selected_line="${2:-1}"; shift 2 ;;
 		-c|--clip) clip=1; selected_line="${2:-1}"; shift 2 ;;
+		-f|--flatten) flatten=1; shift 2 ;;
 		--) shift; break ;;
 	esac done
 
-	[[ $err -ne 0 || ( $qrcode -eq 1 && $clip -eq 1 ) ]] && die "Usage: $PROGRAM $COMMAND [--clip[=line-number],-c[line-number]] [--qrcode[=line-number],-q[line-number]] [pass-name]"
+	[[ $err -ne 0 || ( $qrcode -eq 1 && $clip -eq 1 ) ]] && die "Usage: $PROGRAM $COMMAND [--clip[=line-number],-c[line-number]] [--qrcode[=line-number],-q[line-number]] [--flatten,-f] [pass-name]"
 
 	local pass
 	local path="$1"
@@ -398,11 +399,20 @@ cmd_show() {
 		fi
 	elif [[ -d $PREFIX/$path ]]; then
 		if [[ -z $path ]]; then
-			echo "Password Store"
+			if [[ $flatten -eq 0 ]]; then
+				echo "Password Store"
+			fi
 		else
 			echo "${path%\/}"
 		fi
-		tree -N -C -l --noreport "$PREFIX/$path" 3>&- | tail -n +2 | sed -E 's/\.gpg(\x1B\[[0-9]+m)?( ->|$)/\1\2/g' # remove .gpg at end of line, but keep colors
+		if [[ "$flatten" -eq "0" ]]; then
+			tree -N -C -l --noreport "$PREFIX/$path" 3>&- | tail -n +2 | sed -E 's/\.gpg(\x1B\[[0-9]+m)?( ->|$)/\1\2/g' # remove .gpg at end of line, but keep colors
+		else
+			local passfiles=( "$PREFIX"/*.gpg "$PREFIX"/**/*.gpg )
+			passfiles=( "${passfiles[@]#"$PREFIX/$path"/}" )
+			passfiles=( "${passfiles[@]%.gpg}" )
+			printf '%s\n' "${passfiles[@]}"
+		fi
 	elif [[ -z $path ]]; then
 		die "Error: password store is empty. Try \"pass init\"."
 	else
-- 
2.54.0



More information about the Password-Store mailing list