Skip to content
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 -l / --files-with-matches option? #26

Closed
Roguelazer opened this issue Sep 23, 2016 · 13 comments
Closed

add -l / --files-with-matches option? #26

Roguelazer opened this issue Sep 23, 2016 · 13 comments
Labels
enhancement An enhancement to the functionality of the software.

Comments

@Roguelazer
Copy link

I use the -l option to grep / ack / ag / etc quite a lot to list files containing matches for further processing in a shell pipeline. Does it seem reasonable as a thing to add to ripgrep?

@BurntSushi
Copy link
Owner

Does -c/--count satisfy your use case?

@andyleejordan
Copy link
Contributor

@BurntSushi at least my use case is generally ag -l something | xargs ..., so -c doesn't work without an intermediate awk or something to strip the count.

@BurntSushi
Copy link
Owner

That's reasonable. grep also has these options, so it seems fine for rg to grow them as well.

@BurntSushi BurntSushi added the enhancement An enhancement to the functionality of the software. label Sep 24, 2016
@andyleejordan
Copy link
Contributor

I was looking at adding it to ucg yesterday... now I'm looking at doing it here (I do like Rust more!) (but no promises; recovering from a cold and might give up to play some video games).

@BurntSushi
Copy link
Owner

@andschwa No worries! I might actually bang this out tonight.

@andyleejordan
Copy link
Contributor

@BurntSushi Hey I just got it working! Let me get some tests and docs written and cleaned up, and I'll open a PR.

@BurntSushi
Copy link
Owner

@andschwa Oh you're quick, awesome, thank you!

@andyleejordan
Copy link
Contributor

@BurntSushi Working, but not finished. Right now it operates almost exactly the same as count but calls printer.path instead of printer.path_count, but doing this right I think includes terminating the search after the first match.

It also should be just as easy to add -L/--files-without-match that just sets files_with_matches and invert_match.

I also think I could share a bit more logic with count... I might open a review to ask for some refactor help.

@andyleejordan
Copy link
Contributor

Tada:

$ ./target/debug/rg -l files_with_matches
src/search_buffer.rs
src/search_stream.rs
src/args.rs

@BurntSushi
Copy link
Owner

Nice!

but doing this right I think includes terminating the search after the first match.

Absolutely, yes. This will probably need to go in both of the searchers, which means making them aware of this parameter as well.

@BurntSushi
Copy link
Owner

I'd be happy to do a review. The printer is due for a bit of refactoring, so don't feel too bad about it.

@andyleejordan
Copy link
Contributor

Aye yai yai... figured out with -L wasn't working (but my quick addition of --files-without-match was); it's already used for --follow, but grep uses -L for this. What do you do in this case?

@BurntSushi
Copy link
Owner

Bah. How about we prefer compatibility with grep (although I got -L from find)... Hmm...

Maybe we can just drop the short hand for --files-without-match altogether?

@andyleejordan andyleejordan mentioned this issue Sep 24, 2016
4 tasks
andyleejordan added a commit to andyleejordan/ripgrep that referenced this issue Sep 25, 2016
Closes BurntSushi#26.

Acts like --count but emits only the paths of files with matches,
suitable for piping to xargs. Both mmap and no-mmap searches terminate
after the first match is found. Documentation updated and tests added.
amsharma91 added a commit to amsharma91/ripgrep that referenced this issue Sep 27, 2016
Closes BurntSushi#26.

Acts like --count but emits only the paths of files with matches,
suitable for piping to xargs. Both mmap and no-mmap searches terminate
after the first match is found. Documentation updated and tests added.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement to the functionality of the software.
Projects
None yet
Development

No branches or pull requests

3 participants