[PATCH v2 0/2] pass {find,ls}: --find: Add flag

Alejandro Colomar alx at kernel.org
Mon Aug 18 08:37:35 UTC 2025


Hi!

Here's a revision of the patch set I sent two years ago.  I've addressed
the comments by Tobias.  Here's what changes in v2:

-  Do not depend on previous patches.  This patch set applies on current
   master.
-  Do not print search terms with --find.
-  Minor changes in commit messages.
-  Minor formatting improvements in the manual page changes.

Here's how the additions to the manual page look like after formatting
(I guess this helps review):

	$ export MANWIDTH=64;
	$ diffman-git HEAD;
	--- HEAD^:man/pass.1
	+++ HEAD:man/pass.1
	@@ -71,6 +71,13 @@ COMMANDS
		       folder by using the tree(1) program. This command
		       is alternatively named list.
	 
	+              If the --find flag is used, find(1) is used in‐
	+              stead; this is useful to be able to reuse the
	+              output as an input to pass show.  Here's an exam‐
	+              ple:
	+
	+                  $ pass ls --find foo/bar/ | xargs pass show;
	+
		grep [GREPOPTIONS] search-string
		       Searches inside each decrypted password file for
		       search-string, and displays line containing
	$ diffman-git HEAD^;
	--- HEAD^^:man/pass.1
	+++ HEAD^:man/pass.1
	@@ -79,11 +79,18 @@ COMMANDS
		       as-is. (Note: the GREP_OPTIONS environment vari‐
		       able functions as well.)
	 
	-       find pass-names...
	+       find [ --find ] pass-names...
		       List names of passwords inside the tree that
		       match pass-names by using the tree(1) program.
		       This command is alternatively named search.
	 
	+              If the --find flag is used, find(1) is used in‐
	+              stead; this is useful to be able to reuse the
	+              output as an input to pass ls.  Here's an exam‐
	+              ple:
	+
	+                  $ pass find --find | xargs pass ls;
	+
		show [ --clip[=line-number], -c[line-number] ] [ --qr‐
		code[=line-number], -q[line-number] ] pass-name
		       Decrypt and print a password named pass-name. If

Below you can find a range-diff.


Have a lovely day!
Alex


Alejandro Colomar (2):
  pass find: --find: Add flag
  pass ls: --find: Add flag

 man/pass.1            | 32 +++++++++++++++++++++++++++++++-
 src/password-store.sh | 40 ++++++++++++++++++++++++++++++++--------
 2 files changed, 63 insertions(+), 9 deletions(-)

Range-diff against v1:
1:  ea93997 ! 1:  8562aaa pass find: Add --find flag
    @@ Metadata
     Author: Alejandro Colomar <alx at kernel.org>
     
      ## Commit message ##
    -    pass find: Add --find flag
    +    pass find: --find: Add flag
     
         This flag modifies the command to use find(1) instead of tree(1).
     
    @@ Commit message
         (3)  Remove the .gpg suffix from files (as is historic behavior of
              pass(1)).
     
    +    As this is intended for scripting (machine readable output), the search
    +    terms are not printed if this flag is used.
    +
         Examples of use:
     
                 $ pass find --find bugzilla
    -            Search Terms: bugzilla
                 www/foss/kernel/bugzilla/
                 www/foss/mozilla/bugzilla/
                 www/foss/gentoo/bugzilla/
                 www/foss/gnu/gcc/bugzilla/
     
                 $ pass find --find kernel
    -            Search Terms: kernel
                 www/foss/kernel/
     
         Those tweaks to the output of find(1) make the output directly usable in
         a subsequent invocation of pass(1):
     
                 $ pass find --find kernel \
    -              | tail -n -1 \
    -              | xargs pass show;
    +              | xargs pass ls;
                 www/foss/kernel
                 ├── bugzilla
                 │   ├── alx.manpages
    @@ Commit message
                 └── smtp
                     └── pass
     
    -    The tail(1) above is to hide the search terms.
    -
    +    Cc: Tobias Girstmair <t-lists at girst.at>
    +    Cc: Fabian Pflug <fabian.pflug at gummu.de>
         Signed-off-by: Alejandro Colomar <alx at kernel.org>
     
      ## man/pass.1 ##
     @@ man/pass.1: .SH COMMANDS
    - as-is.
    - (Note: the \fIGREP_OPTIONS\fP environment variable functions as well.)
    + .BR grep (1)
    + as-is. (Note: the \fIGREP_OPTIONS\fP environment variable functions as well.)
      .TP
     -\fBfind\fP \fIpass-names\fP...
     +\fBfind\fP [ \fI\-\-find\fP ] \fIpass-names\fP...
      List names of passwords inside the tree that match \fIpass-names\fP by using the
      .BR tree (1)
    - program.
    - This command is alternatively named \fBsearch\fP.
    + program. This command is alternatively named \fBsearch\fP.
    ++.IP
     +If the
     +.I \-\-find
     +flag is used,
     +.BR find (1)
     +is used instead;
     +this is useful to be able to reuse the output as an input to
    -+.IR "pass ls" .
    ++.IR pass\~ls .
     +Here's an example:
     +.IP
     +.in +4n
     +.EX
    -+$ pass find \-\-find foo | tail \-n \-1 | xargs pass ls
    ++.RB $\~ "pass find \-\-find | xargs pass ls" ;
     +.EE
     +.in
      .TP
    - \fBshow\fP [ \fI\-\-clip\fP[=\fIline-number\fP], \fI\-c\fP[\fIline-number\fP] ] [ \fI\-\-qrcode\fP[=\fIline-number\fP], \fI\-q\fP[\fIline-number\fP] ] \fIpass-name\fP
    - Decrypt and print a password named \fIpass-name\fP.
    + \fBshow\fP [ \fI--clip\fP[=\fIline-number\fP], \fI-c\fP[\fIline-number\fP] ] [ \fI--qrcode\fP[=\fIline-number\fP], \fI-q\fP[\fIline-number\fP] ] \fIpass-name\fP
    + Decrypt and print a password named \fIpass-name\fP. If \fI--clip\fP or \fI-c\fP
     
      ## src/password-store.sh ##
     @@ src/password-store.sh: cmd_show() {
    @@ src/password-store.sh: cmd_show() {
     +	esac done
     +
      	[[ $# -eq 0 ]] && die "Usage: $PROGRAM $COMMAND pass-names..."
    - 	IFS="," eval 'echo "Search Terms: $*"'
    +-	IFS="," eval 'echo "Search Terms: $*"'
      	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'
     +
    @@ src/password-store.sh: cmd_show() {
     +
     +		find -L "$PREFIX" -iname "${terms%|*}" | sed 's,$,/,' | sed "s/^.\{$n\}//" | sed 's,\.gpg/$,,'
     +	else
    ++		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'
     +	fi
      }
2:  972dcbb ! 2:  1a5b0a2 pass ls: Add --find flag
    @@ Metadata
     Author: Alejandro Colomar <alx at kernel.org>
     
      ## Commit message ##
    -    pass ls: Add --find flag
    +    pass ls: --find: Add flag
     
         Similarly to `pass find --find`, this flag changes the `pass ls` command
         to use find(1) instead of tree(1).
    @@ Commit message
         Examples of use:
     
                 $ pass find --find kernel \
    -              | tail -n -1 \
    -              | xargs ./password-store.sh ls --find;
    +              | xargs pass ls --find;
                 www/foss/kernel/
                 www/foss/kernel/smtp/
                 www/foss/kernel/smtp/pass
    @@ Commit message
                 www/foss/kernel/bugzilla/alx/pass
     
                 $ pass find --find kernel \
    -              | tail -n -1 \
                   | xargs pass ls --find \
    -              | tail -n1 \
                   | xargs pass show;
                 pw
     
    +    Cc: Tobias Girstmair <t-lists at girst.at>
    +    Cc: Fabian Pflug <fabian.pflug at gummu.de>
         Signed-off-by: Alejandro Colomar <alx at kernel.org>
     
      ## man/pass.1 ##
     @@ man/pass.1: .SH COMMANDS
    + by using the
      .BR tree (1)
    - program.
    - This command is alternatively named \fBlist\fP.
    + program. This command is alternatively named \fBlist\fP.
    ++.IP
     +If the
     +.I \-\-find
     +flag is used,
     +.BR find (1)
     +is used instead;
     +this is useful to be able to reuse the output as an input to
    -+.IR "pass show" .
    ++.IR pass\~show .
     +Here's an example:
     +.IP
     +.in +4n
     +.EX
    -+$ pass ls \-\-find foo/bar/ | tail \-n1 | xargs pass show
    ++.RB $\~ "pass ls \-\-find foo/bar/ | xargs pass show" ;
     +.EE
     +.in
    -+.TP
      .TP
      \fBgrep\fP [\fIGREPOPTIONS\fP] \fIsearch-string\fP
      Searches inside each decrypted password file for \fIsearch-string\fP, and displays line
-- 
2.50.1



More information about the Password-Store mailing list