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

Ability to filter by file paths (ripgrep -g) #9

Closed
simonw opened this issue Nov 28, 2020 · 6 comments
Closed

Ability to filter by file paths (ripgrep -g) #9

simonw opened this issue Nov 28, 2020 · 6 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Nov 28, 2020

ripgrep has robust support for this: https://github.com/BurntSushi/ripgrep/blob/master/GUIDE.md#manual-filtering-globs

Suggested here: https://news.ycombinator.com/item?id=25236933

@simonw simonw added the enhancement New feature or request label Nov 28, 2020
@simonw simonw changed the title Ability to filter by file paths Ability to filter by file paths (ripgrep -g) Nov 28, 2020
@simonw
Copy link
Owner Author

simonw commented Nov 28, 2020

I'm going to support multiple ?glob= querystring arguments which will be passed to rg.

@simonw
Copy link
Owner Author

simonw commented Nov 28, 2020

    -g, --glob <GLOB>...                    
            Include or exclude files and directories for searching that match the given
            glob. This always overrides any other ignore logic. Multiple glob flags may be
            used. Globbing rules match .gitignore globs. Precede a glob with a ! to exclude
            it. If multiple globs match a file or directory, the glob given later in the
            command line takes precedence.
            
            When this flag is set, every file and directory is applied to it to test for
            a match. So for example, if you only want to search in a particular directory
            'foo', then *-g foo* is incorrect because 'foo/bar' does not match the glob
            'foo'. Instead, you should use *-g 'foo/**'*.

@simonw
Copy link
Owner Author

simonw commented Nov 28, 2020

I'm a bit confused about what is meant to happen if you pass -g multiple times.

Globs are interpreted in exactly the same way as .gitignore patterns. That is, later globs will override earlier globs. For example, the following command will search only *.toml files:

$ rg clap -g '!*.toml' -g '*.toml'

I was expecting these to act as "AND" rules - so -g '*.py' -g 'datasette/**' would return all .py files in my datasette/ directory. That doesn't appear to be happening - I get back results for all .py files ignoring whether they are inside datasette/ no matter which order I pass the -g flags in.

@simonw
Copy link
Owner Author

simonw commented Nov 28, 2020

I'm going to support ?glob=&glob= in the querystring (as an advanced power user feature) but I'm not going to expose it in the UI, since it doesn't behave the way I expected it to.

@simonw simonw closed this as completed in de94fc4 Nov 28, 2020
simonw added a commit that referenced this issue Nov 28, 2020
simonw added a commit that referenced this issue Nov 28, 2020
@simonw
Copy link
Owner Author

simonw commented Nov 28, 2020

Those new examples:

@simonw
Copy link
Owner Author

simonw commented Nov 28, 2020

ripgrep__with__AsyncClient

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant