You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think --after-context (-A) and --context (-C) should have the same precedence as --before-context (-B), when being combined with --max-count (-m), but they do not:
$ cat > rgtest.txt <<EOF> a> b> c> d> e> EOF$ rg -B2 c rgtest.txt1-a2-b3:c$ rg -C2 c rgtest.txt1-a2-b3:c4-d5-e$ rg -A2 c rgtest.txt3:c4-d5-e$ # and now with --max-count:$ rg -B2 c -m1 rgtest.txt1-a2-b3:c$ rg -C2 c -m1 rgtest.txt1-a2-b3:c$ rg -A2 c -m1 rgtest.txt3:c
From my expectations, -B works correctly, -C works like -B which is unexpected, and -A has no effect at all.
My use case is to show a colleague one instance of many repeated matches, but also with some context. If -A combined with -m would yield the same result as with -B, then my use case would have been fulfilled.
I am using ripgrep-0.3.2-1.fc24.x86_64, packaged for Fedora through copr (by carlgeorge-ripgrep).
Thanks for a great program! (edit: removed trailing whitespace in code block)
The text was updated successfully, but these errors were encountered:
Thanks for the bug report. This is definitely a bug. But I don't think it has anything to do with precedence specifically. For example:
[andrew@Cheetah ripgrep-402] cat > rgtest.txt <<EOF
> a
> b
> c
> d
> e
> a
> b
> c
> d
> e
> EOF
[andrew@Cheetah ripgrep-402] rg -C2 c -m1 rgtest.txt
1-a
2-b
3:c
[andrew@Cheetah ripgrep-402] rg -C2 c -m2 rgtest.txt
1-a
2-b
3:c
4-d
5-e
6-a
7-b
8:c
Notice that in the last example, the "after" context for the first match is printed correctly. Only the last match loses it.
This is probably just a bug in the search code where it neglects to print the context after the last match if it decides to quit early. I'll note that grep handles this correctly:
[andrew@Cheetah ripgrep-402] grep -C2 c -m2 rgtest.txt
a
b
c
d
e
a
b
c
d
e
I think
--after-context
(-A
) and--context
(-C
) should have the same precedence as--before-context
(-B
), when being combined with--max-count
(-m
), but they do not:From my expectations,
-B
works correctly,-C
works like-B
which is unexpected, and-A
has no effect at all.My use case is to show a colleague one instance of many repeated matches, but also with some context. If
-A
combined with-m
would yield the same result as with-B
, then my use case would have been fulfilled.I am using ripgrep-0.3.2-1.fc24.x86_64, packaged for Fedora through copr (by carlgeorge-ripgrep).
Thanks for a great program! (edit: removed trailing whitespace in code block)
The text was updated successfully, but these errors were encountered: