-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an option similar to -o, --only-matching #34 #422
Conversation
fdec3ca
to
fb99367
Compare
@kpp Thank you! You're on a roll. I've wanted this for a while but just didn't get the chance to ever sit down and do it. I think things might be a bit trickier than this though. For example, what does it mean to combine the
So basically, GNU grep doesn't show any of the surrounding context lines, but it continues to print the context separators when applicable. What we need to do is decide if this behavior was actually intended or not, and think through what option actually makes sense to do. I think we should also address the interaction between this flag and others like |
fb99367
to
3877493
Compare
Well, it depends on how it is documented ;D . Would you please prepare examples for me showing expected behavior? |
Seems like this behavior even better for me:
|
From grep man page:
|
Sure. Sorry I wasn't clear, but I'm not quite sure myself what the behavior should be. Looking at your examples, I'm inclined to agree with you. I guess I'm just nervous... Why does GNU grep stomp on context support when We still need to figure out |
Seems like
|
[12:18] -ChanServ- [#gnu] Welcome to #gnu, the official channel of the GNU Project. Please read and follow http://www.gnu.org/server/irc-rules.html. |
Does not seem confusing to me
|
@kpp Yeah, I'm with you. I'm not really buying what they're selling, especially when the context separators are still printed. So I think the only thing left to think about is the |
[15:13] <Learn_C> bill-auger, not clear enough. MAN page says "grep, egrep, fgrep, rgrep - print lines matching a pattern", according to that, there should be no -A -B -C, because they don't match a pattern |
Using the
|
The man page for GNU grep says this about the
To me, this doesn't imply anything about contexts. The option only applies to matching lines. It doesn't say, "print only matching lines," it says, "print only the non-empty matched parts of a matching line." ... In any case, this navel gazing about whether GNU grep does the "right" thing or not is probably not going to go anywhere productive. I think what I'd like to know is if there's a practical purpose for the |
Well, I agree with you. Lets talk about no
with
no
|
@kpp Sorry, but could you use simpler commands please? Drop the |
It tries to multiple lines by n found occurrences. Than it replaces found part with replacer and we get duplicate lines with no meaning.
|
I bet we should prohibit the use of
Should we show only |
|
@kpp I don't quite have the time to think about this. Is it possible to modify how |
Yes, it is possible. Just tell me your expectations) |
I think it doesn't really matter too much which method you take (suppressing I tend to lean towards grep's way being more "correct" (minus still printing context separators...that doesn't make sense), but the proposed ripgrep way is more flexible and I'd totally find it fine to see it implemented. I say. "correct" as in "do what I want, not what I say." How does the proposed ripgrep handle this:
I would find this less correct, and harder to pipe:
Because technically I'd think of the Having said this, the proposed ripgrep way allows one to actually see (minus caveats above) context when showing A way to kind of sidestep this is to use a soft override. Whichever conflicting arg comes last wins. Meaning Just my thoughts. :-) |
@kbknapp That's an interesting point. I suppose the only way to really figure out why using What I'm trying to say is this: under what circumstances is the behavior of GNU grep desirable (modulo the weirdness of emitting context separators)? |
I totally agree, and I can't really think of a valid reason why someone would do that unless it's just scripted as a default behavior...which still seems strange but it's all I can come up with 😟 |
@BurntSushi, @kbknapp are you happy to see how context and |
@kpp I think I'm happy with the current interaction. My mind could be changed by use cases. I realize I'm still on the hook for figuring out how |
How about:
|
3877493
to
f525473
Compare
I've merged this in 90a11de after a rebase, squash and a tweak to the While I don't particularly like that we now have conflicting flags, I also don't know what the right behavior for combining |
Guess someone beat me to implementing So, as I mentioned in #308, I think the best combination for |
Errmm, OK, so I forgot to close this PR after I did a manual merge in 90a11de. :-) |
Fixes #34
Example: