4 ms·
You can't accomplish that with the -g glob flag?
by apeace 9y ago
You can't accomplish that with the -g glob flag?
- sillysaurus3 9y ago$ 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.
- beefsack 9y agoThis is because of the shell, not the executable. The shell will translate `*` into a relevant list of files before passing them to the executable.
- coldtea 9y ago>I see, you have to do "rg -g '.l' foo" 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).
- burntsushi 9y ago`ag -G l` and `rg -g '{STAR}.l'` are not equivalent. The former will match any file name that contains `l` where as the latter will match any file name that ends with `.l`. (ag's -G flag accepts a regex with match-anywhere semantics, where rg's -g flag accepts a glob that matches on the basename of a file, e.g., `rg -g Makefile` will search all files name `Makefile`.) 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.
- ephl 9y agoIf you're using bash you don't need single quotes: rg -g*.l foo