[PATCH] Change tree to an optional depend and add support for exa

Wu Zhenyu wuzhenyu at ustc.edu
Sat Nov 5 15:53:22 UTC 2022


---
 src/password-store.sh | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/password-store.sh b/src/password-store.sh
index 22e818f..cd844f8 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -378,7 +378,7 @@ cmd_show() {
 
 	[[ $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]"
 
-	local pass
+	local pass tree
 	local path="$1"
 	local passfile="$PREFIX/$path.gpg"
 	check_sneaky_paths "$path"
@@ -402,7 +402,14 @@ cmd_show() {
 		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 command -v exa &> /dev/null; then
+			tree="exa --color=always --icons --tree"
+		elif command -v tree &> /dev/null; then
+			tree="tree -N -C -l --noreport"
+		else
+			die "Error: please install exa/tree firstly!"
+		fi
+		$tree "$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
 	elif [[ -z $path ]]; then
 		die "Error: password store is empty. Try \"pass init\"."
 	else
-- 
2.38.1






More information about the Password-Store mailing list