The grep option --color=auto is used to color the output if and only if output
is to a terminal. This makes it more suitable for scripts.
The grep option --label=$label is used to print any string to appear as the
filename if grep searches stdin. This makes it possible to display the
password name on the same line as the match. This makes it more suitable for
further line wise processing in scripts.
The man page falsely stated that the filename would be displayed with the
matches. Actually the password name is displayed.
---
man/pass.1 | 4 ++--
src/password-store.sh | 15 +++++----------
2 files changed, 7 insertions(+), 12 deletions(-)
diff --git a/man/pass.1 b/man/pass.1
index e1fe605..968f418 100644
--- a/man/pass.1
+++ b/man/pass.1
@@ -75,8 +75,8 @@ by using the
program. This command is alternatively named \fBlist\fP.
.TP
\fBgrep\fP \fIsearch-string\fP
-Searches inside each decrypted password file for \fIsearch-string\fP, and displays line
-containing matched string along with filename. Uses
+Searches inside each decrypted password file for \fIsearch-string\fP, and displays matching
+lines along with password names. Uses
.BR grep (1)
for matching. Make use of the \fIGREP_OPTIONS\fP environment variable to set particular
options.
diff --git a/src/password-store.sh b/src/password-store.sh
index d535a74..83ecc3a 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -339,17 +339,12 @@ cmd_find() {
cmd_grep() {
[[ $# -ne 1 ]] && die "Usage: $PROGRAM $COMMAND search-string"
- local search="$1" passfile grepresults
+ local search="$1" passfile label
while read -r -d "" passfile; do
- grepresults="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | grep --color=always "$search")"
- [ $? -ne 0 ] && continue
- passfile="${passfile%.gpg}"
- passfile="${passfile#$PREFIX/}"
- local passfile_dir="${passfile%/*}/"
- [[ $passfile_dir == "${passfile}/" ]] && passfile_dir=""
- passfile="${passfile##*/}"
- printf "\e[94m%s\e[1m%s\e[0m:\n" "$passfile_dir" "$passfile"
- echo "$grepresults"
+ label="${passfile%.gpg}"
+ label="${label#"$PREFIX"}"
+ label="${label#/}"
+ $GPG -d "${GPG_OPTS[@]}" "$passfile" | grep --color=auto --label="$label" -H "$search"
done < <(find -L "$PREFIX" -iname '*.gpg' -print0)
}
_______________________________________________
Password-Store mailing list
[email protected]
http://lists.zx2c4.com/mailman/listinfo/password-store