Hi Jason,

here's the matching patch with the documentation and test.

norbi

On 05/24/18 13:26, Jason A. Donenfeld wrote:
> Looks good to me!
> _______________________________________________
> Password-Store mailing list
> [email protected]
> https://lists.zx2c4.com/mailman/listinfo/password-store

From bd6073150922866a3e31a0f86498798baf0b9ee6 Mon Sep 17 00:00:00 2001
From: Norbert Buchmueller <[email protected]>
Date: Tue, 17 Apr 2018 00:10:34 +0200
Subject: [PATCH] add tests and documentation of passing options to grep(1)

---
 man/pass.1            |  7 ++++---
 src/password-store.sh |  4 ++--
 tests/t0400-grep.sh   | 12 ++++++++++++
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/man/pass.1 b/man/pass.1
index e842178..173eef4 100644
--- a/man/pass.1
+++ b/man/pass.1
@@ -81,12 +81,13 @@ by using the
 .BR tree (1)
 program. This command is alternatively named \fBlist\fP.
 .TP
-\fBgrep\fP \fIsearch-string\fP
+\fBgrep\fP [ \fIGREPOPTIONS\fP ] \fIsearch-string\fP
 Searches inside each decrypted password file for \fIsearch-string\fP, and displays line
 containing matched string along with filename. Uses
 .BR grep (1)
-for matching. Make use of the \fIGREP_OPTIONS\fP environment variable to set particular
-options.
+for matching. \fIGREPOPTIONS\fP are passed to
+.BR grep (1)
+as-is. (Note: the \fIGREP_OPTIONS\fP environment variable still works, but it is deprecated.)
 .TP
 \fBfind\fP \fIpass-names\fP...
 List names of passwords inside the tree that match \fIpass-names\fP by using the
diff --git a/src/password-store.sh b/src/password-store.sh
index 19b3124..2651dd8 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -266,7 +266,7 @@ cmd_usage() {
 	    $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.
-	    $PROGRAM grep search-string
+	    $PROGRAM grep [ GREPOPTIONS ] search-string
 	        Search for password files containing search-string when decrypted.
 	    $PROGRAM insert [--echo,-e | --multiline,-m] [--force,-f] pass-name
 	        Insert new password. Optionally, echo the password back to the console
@@ -395,7 +395,7 @@ cmd_find() {
 }
 
 cmd_grep() {
-	[[ $# -lt 1 ]] && die "Usage: $PROGRAM $COMMAND search-string"
+	[[ $# -lt 1 ]] && die "Usage: $PROGRAM $COMMAND [ GREPOPTIONS ] search-string"
 	local passfile grepresults
 	while read -r -d "" passfile; do
 		grepresults="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | grep --color=always "$@")"
diff --git a/tests/t0400-grep.sh b/tests/t0400-grep.sh
index 206377f..b244cf4 100755
--- a/tests/t0400-grep.sh
+++ b/tests/t0400-grep.sh
@@ -18,4 +18,16 @@ test_expect_success 'Make sure grep prints normal lines' '
 	grep -q "They are" <<<"$results"
 '
 
+test_expect_success 'Test passing the "-i" option to grep' '
+	"$PASS" init $KEY1 &&
+	"$PASS" insert -e blah1 <<<"I wonder..." &&
+	"$PASS" insert -e blah2 <<<"Will it ignore" &&
+	"$PASS" insert -e blah3 <<<"case when searching?" &&
+	"$PASS" insert -e folder/blah4 <<<"Yes, it does. Wonderful!" &&
+	results="$("$PASS" grep -i wonder)" &&
+	[[ $(wc -l <<<"$results") -eq 4 ]] &&
+	grep -q blah1 <<<"$results" &&
+	grep -q blah4 <<<"$results"
+'
+
 test_done
-- 
2.11.0

_______________________________________________
Password-Store mailing list
[email protected]
https://lists.zx2c4.com/mailman/listinfo/password-store

Reply via email to