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

Include/exclude searched files with implicit wildcard or regex (ag -G) #2314

Open
oandrew opened this issue Sep 28, 2022 · 4 comments
Open
Labels
enhancement An enhancement to the functionality of the software. question An issue that is lacking clarity on one or more points.

Comments

@oandrew
Copy link

oandrew commented Sep 28, 2022

Describe your feature request

First, thanks for ripgrep.

There is one feature in silversearcher (ag) that's holding me back - filter file paths with regex e.g. ag <pattern> -G <regex>.
ripgrep seems to support only globs (I'm guessing for performance reasons?)

  • This means in most cases (partial match somewhere in the path) you have to type extra characters (wildcard + quotes):
$ rg -g '*test*' func
$ ag -G test func
  • some things are not possible to express due to limitations of globs.

99% of the time I simply use it to do a partial match, so having something like rg -G test func as shortcut to rg -g '*test*' func would totally resolve it for me.

So this boils down to:

  1. (simple) Could we have a new flag -G <glob> that's similar to -g <glob> but <glob> is implicitly surrounded with wildcards? Then you could avoid typing and escaping * in most cases.
    e.g. rg -G test func would be equivalent to rg -g '*test*' func
  2. (complex) rg -G <pattern> could accept a regex which would allow other use cases in addition to partial match.

Would you consider a PR for the first approach?

Thanks!

@BurntSushi
Copy link
Owner

It would be good to search the tracker first... :-) Dupe of #48, #54, #75, #91 (lots of discussion here), #193, #285.

There's just so many different ways to already do this that I don't see the point of adding a new flag for it. rg --files | rg test can be easily put into an alias or a wrapper shell script. Here's mine:

https://github.com/BurntSushi/dotfiles/blob/2f58eedf3b7f7dae7f0a7cea1a641459e25e5d07/.aliasrc#L111-L121

You could also use a purpose driven tool specifically for searching by file name: https://github.com/sharkdp/fd/

@BurntSushi BurntSushi added duplicate An issue that is duplicative of another. wontfix A feature or bug that is unlikely to be implemented or fixed. labels Sep 28, 2022
@oandrew
Copy link
Author

oandrew commented Sep 28, 2022

@BurntSushi I wasn't referring to file search, but filtering files included in result (rg --glob). I searched the tracker but didn't find anything similar.

Updated the title to be less confusing

@oandrew oandrew changed the title Filter files with implicit wildcard or regex (ag -G) Include/exclude files with implicit wildcard or regex (ag -G) Sep 28, 2022
@oandrew oandrew changed the title Include/exclude files with implicit wildcard or regex (ag -G) Include/exclude searched files with implicit wildcard or regex (ag -G) Sep 28, 2022
@BurntSushi
Copy link
Owner

Ooooo, I see. Sorry, I missed that.

I'll re-open this for now. I don't have time to respond, but I'm not quite inclined to accept this, at least as of now. ripgrep needs its filtering internals (and interface) overhauled at some point, so I'd rather not add anything substantially new to it as of now.

@BurntSushi BurntSushi reopened this Sep 28, 2022
@BurntSushi BurntSushi added enhancement An enhancement to the functionality of the software. question An issue that is lacking clarity on one or more points. and removed duplicate An issue that is duplicative of another. wontfix A feature or bug that is unlikely to be implemented or fixed. labels Sep 28, 2022
@relicode
Copy link

Minimalistic POSIX-compatible script with wildcard support:

#!/bin/sh

PATTERN="$1"
shift

(for DIR in "${@:-.}"; do rg --files "$DIR"; done) | rg "$PATTERN"

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. question An issue that is lacking clarity on one or more points.
Projects
None yet
Development

No branches or pull requests

3 participants