by sillysaurus3 · 9y ago · 0 comments
$ rg -g l foo
No files were searched, which means ripgrep probably
applied a filter you didn't expect. Try running again
with --debug.
Empirically not! :)EDIT: I see, you have to do "rg -g '*.l' foo". Well, that's a bit silly. Why force people to put asterisks inside of single quotes on the command line? Asterisks have a specific meaning in a shell setting. It's five times longer than -G l, the ag equivalent.
EDIT: Thanks for all the explanations.
The asterisk is part of standard globbing. You can also write it as `rg -g \{STAR}.l foo`, if you find that nicer.
If you want to match a list of extensions, then you can fall back to standard glob syntax: `rg -g '{STAR}.{foo,bar,baz}' pattern`. Or, as others have mentioned, if you're searching for standard file types, you can use the `-t/--type` flag. e.g., To search HTML, CSS and Javascript: `rg -tjs -thtml -tcss foo`.
Basically, ripgrep's `-g` flag is supposed to match grep's `--include` flag, which also uses globs and requires the same type of ceremony. I'd like to add --include/--exclude to match grep's behavior more precisely (which is based on user complaints wanting those flags).
N.B. Replace {STAR} in text above with a literal asterisk symbol.
Actually it's just:
rg -g '*.js' query
And if it's a known file type, like js, you can do (-t type): rg -g -t js
>Why force people to put asterisks inside of single quotes on the command line?*Because else the shell will auto-expand the asterisk before it even gets to rg, and rg will instead get the expanded list of files that match the pattern. E.g. if you have
a.js b.js /foo
in a folder, then: rg -g *.js query
will be expanded by your shell to: rg -g a.js b.js query
and THEN run. rg will never see the asterisk in that case (and it also wont search inside /foo). rg -g*.l foo