pass list

Pierre Prinetti pierreprinetti at redhat.com
Wed Apr 14 17:57:36 UTC 2021


>From 23752d9a1d3d8f86022a1464a8001e7d50452f6e Mon Sep 17 00:00:00 2001
From: Pierre Prinetti <pierreprinetti at redhat.com>
Date: Wed, 14 Apr 2021 19:26:45 +0200
Subject: [PATCH] Add --flat option to show

The --flat flag to {show,ls,list} makes pass list multiple entries in a
flat list form, rather than in a tree form.

The new flag applies when no argument is passed, or when the argument
corresponds to a directory.
---
 src/password-store.sh | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/password-store.sh b/src/password-store.sh
index 77f3eda..b791139 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -364,17 +364,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 flat=0
+    opts="$($GETOPT -o q::c:: -l qrcode::,clip::,flat -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 ;;
+        --flat) flat=1; shift 1 ;;
         --) 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]] [--flat] [pass-name]"

     local pass
     local path="$1"
@@ -395,12 +396,17 @@ cmd_show() {
             fi
         fi
     elif [[ -d $PREFIX/$path ]]; then
-        if [[ -z $path ]]; then
-            echo "Password Store"
+        if [[ $flat -eq 1 ]]; then
+            local prefix_realpath="$(realpath "$PREFIX")"
+            find "$PREFIX/$path" -type f -name '*.gpg' | while read
-r line; do echo "${line##"${prefix_realpath}/"}"; done | sed -E
's/\.gpg$//g'
         else
-            echo "${path%\/}"
+            if [[ -z $path ]]; then
+                echo "Password Store"
+            else
+                echo "${path%\/}"
+            fi
+            tree -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
         fi
-        tree -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
     elif [[ -z $path ]]; then
         die "Error: password store is empty. Try \"pass init\"."
     else
-- 
2.30.2

On Wed, 14 Apr 2021 at 17:20, Dacoda Strack <dacoda.strack at gmail.com> wrote:
>
> On Wed, Apr 14, 2021 at 04:01:50PM +0300, Greg Minshall wrote:
> > Pierre,
> >
> > > I am willing to write a patch if we find consensus.
> >
> > i'd be a fan.  and, if highlighting could somehow also be controlled,
> > that would be great.
> >
> > cheers, Greg
>
> This sounds great to me, I wonder if something naive like
>
> find $PASSWORD_STORE -type f -name '*.gpg'
>
> with some additional sed to clean up the path would get us where we need
> to be
>
> I think I'm going to have a small local fork and build RPMs with some
> of these minor patches.
>



More information about the Password-Store mailing list