[PATCH v3] Ensure compatibility with tree 2.0.

Marius Bakke marius at gnu.org
Sun Jan 16 18:57:01 UTC 2022


Tree 2.0 and later will unconditionally ignore all options and write
JSON data on file descriptor 3 when available, which causes problems
for the test harness and other scripts that use FD 3.  Work around by
closing descriptor 3 for the 'tree' command.
---
 src/password-store.sh | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
---
Changes in v3:
  * Close descriptor 3 for 'tree' instead of redirecting to temporary fd.

diff --git a/src/password-store.sh b/src/password-store.sh
index aef8d72..17d09cf 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -402,7 +402,12 @@ cmd_show() {
 		else
 			echo "${path%\/}"
 		fi
-		tree -N -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
+		# 'tree' 2.0 and later writes JSON output on descriptor 3 when
+		# present, so move it temporarily in case it happens to be set.
+		tree -N -C -l --noreport "$PREFIX/$path" 3>&- |
+			tail -n +2 |
+			# remove .gpg at end of line, but keep colors
+			sed -E 's/\.gpg(\x1B\[[0-9]+m)?( ->|$)/\1\2/g'
 	elif [[ -z $path ]]; then
 		die "Error: password store is empty. Try \"pass init\"."
 	else
@@ -414,7 +419,10 @@ cmd_find() {
 	[[ $# -eq 0 ]] && die "Usage: $PROGRAM $COMMAND pass-names..."
 	IFS="," eval 'echo "Search Terms: $*"'
 	local terms="*$(printf '%s*|*' "$@")"
-	tree -N -C -l --noreport -P "${terms%|*}" --prune --matchdirs --ignore-case "$PREFIX" | tail -n +2 | sed -E 's/\.gpg(\x1B\[[0-9]+m)?( ->|$)/\1\2/g'
+	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'
 }
 
 cmd_grep() {
-- 
2.34.0



More information about the Password-Store mailing list