Hello,
as I'm unsure, if compatibility is the aim of the project. The commit
before on this line aimed to be compatible with tree 2.0 [1]. Since find
and grep is already a dependency, sure I provide a version without tree.
I adapted the change, left sort out as this could be unintended use and
appended suffix-removal after the first command.
There are similar approaches with the aim to be POSIX-compatible [2].
Anyways, I'm unsure if they have the same wiede adoption and mass of
compatible clients.
But to allow different behavior here could be a compatible workaround.
Any further suggestions are well appreciated.
Kind Regards
Andreas
[1]
https://git.zx2c4.com/password-store/commit/?id=eea24967a002a2a81ae9b97a1fe972b5287f3a09
[2] https://github.com/dylanaraps/pash
Am 19.07.22 um 12:06 schrieb Kjetil Torgrim Homme:
On 19/07/2022 11:37, Magnus Sandberg wrote:
Hi,
After a few minutes of manual testing at my shell prompt, I guess
this one does the same;
find ${PREFIX} -type f -name '*.gpg' | grep -i "${terms}" \
| sed -E "s|^${PREFIX}/||" | sed -E 's/\.gpg$//' | sort
Assuming that 'grep -i "${terms}"' would give the same result as
'tree ... -P "${terms%|*}" ...'
I would prefer a version which is not reliant on tree, too. especially
since it seems very fragile to try to remove the glyphs used for the
tree in the output. (in fact, on my EL7 box, the version of tree
shipped with the distro is incompatible with pass, so I run find(1)
manually instead!)
A small point - I think it is better to remove the prefix and .gpg
suffix before the grep to avoid unwanted matches (e.g., searching for
"home" :)
From 0dcac0861fa80eddb5fd6389d266f07fd8feec91 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20K=C3=B6lbl?= <[email protected]>
Date: Tue, 24 May 2022 19:14:31 +0200
Subject: [PATCH] Add option --flat
Support a computable way to find passwords.
By adding the flag --flat after "pass find" it prints paths of found
passwords without colors or indentions.
---
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..926f0f5 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -282,8 +282,8 @@ cmd_usage() {
Selectively reencrypt existing passwords using new gpg-id.
$PROGRAM [ls] [subfolder]
List passwords.
- $PROGRAM find pass-names...
- List passwords that match pass-names.
+ $PROGRAM find [--flat] pass-names...
+ List passwords that match pass-names and optionally print it without colors, indentions or special characters.
$PROGRAM [show] [--clip[=line-number],-c[line-number]] pass-name
Show existing password and optionally put it on the clipboard.
If put on the clipboard, it will be cleared in $CLIP_TIME seconds.
@@ -412,9 +412,19 @@ cmd_show() {
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" 3>&- | tail -n +2 | sed -E 's/\.gpg(\x1B\[[0-9]+m)?( ->|$)/\1\2/g'
+ local opts flat="0"
+ case $1 in
+ -f|--flat) flat=1; shift ;;
+ --) shift; break ;;
+ esac
+ if [ $flat -eq 0 ]; then
+ local terms="*$(printf '%s*|*' "$@")"
+ 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'
+ else
+ local terms="$@"
+ find ${PREFIX} -type f -name '*.gpg' | grep -i "${terms}" | sed -E "s|^${PREFIX}/||" | sed -E 's/\.gpg$//'
+ fi
}
cmd_grep() {
--
2.35.1