8 ms·
Don't use grep. Use ag[0], which is specifically designed for searching code. It's much faster, honors .gitignore, and the output can be piped back through grep
by fredley 7y ago
Don't use grep. Use ag[0], which is specifically designed for searching code. It's much faster, honors .gitignore, and the output can be piped back through grep if you like.
ag FooBar | grep -v Baz
It's in brew/apt/yum etc as `the_silver_searcher` (although brew install ag works fine too).
0: https://github.com/ggreer/the_silver_searcher https://github.com/ggreer/the_silver_searcher
- hawski 7y agoIt's not much faster as in "over 50% faster". It's faster to invoke as you have much less to type to scan recursively with ignore list. However I find that in many projects .gitignore is too extensive, because it includes generated code, that many times is quite informative. Then it's still nice to use those alternative grep-likes, but not by much. Besides, when you can't install easily it's hard to beat something that it's already there and everywhere else.
- tigroferoce 7y agoI second ag too. Not because it's faster, but because it is developer-oriented so it has sane defaults for searching into code.
- war1025 7y agoI find `git grep` to be quite sufficient. A real pain when trying to look through code that isn't in git though.
- Whoaa512 7y agoyou can just add `--no-index` to search in non-git repositories
- Joeboy 7y agoIs there a reason to use ag rather than rg? afair the latter was a lot faster when I tried it (on ubuntu / intel).
- dkarl 7y agoSame experience here, started with ack and switched to ag and then to rg for speed. I've found them roughly equivalent in functionality, but for those who need specific features here's a link to a feature comparison table: https://beyondgrep.com/feature-comparison/ https://beyondgrep.com/feature-comparison/
- burntsushi 7y agoThat table is quite out of date for ripgrep, which has added a number of features. See: https://github.com/beyondgrep/website/issues/97 https://github.com/beyondgrep/website/issues/97
- dmix 7y agoThanks for ripgrep, I use it daily and was recently going through the source code to learn how to build production quality Rust apps! (https://github.com/BurntSushi/ripgrep https://github.com/BurntSushi/ripgrep)
- wyldfire 7y agoPretty sure that rg is a successor to ag, so most people who use `ag` are just ones who haven't heard of `rg` yet. Well, there's no true hierarchy/succession order but rg was written after ag was.
- burntsushi 7y agoYes, this is true, although ripgrep is more of a hybrid than ag is. ag has numerous problems with being treated as a normal `grep` tool, where as ripgrep does not. (Although, to be clear, ripgrep is not POSIX compatible.)
- justinmeiners 7y agowhy not use a posix standard tool which is available everywhere? I appreciate the suggestion, but its worded a little strongly.
- valbaca 7y ago+1 Here's why: ag provides sane default and settings for developers. grep is ubiquitous and great, but to do what most developers want it requires some guidance, whereas ag focuses on being what you want most of the time. What I mean by that is that I enjoy the smart-case sensitivity (as in, if there are not caps in my pattern, then it defaults to case-insensitive but if I have any caps in my pattern, it uses case-sensitive) or fast filename searching with -g or both with -G. I've tried rg and while it was faster, it also didn't provide as good support for filename searching. Ag is still what I consider "so fast I almost don't believe it" It's like the 'tldr' command (https://tldr.sh/ https://tldr.sh/). Of course I still use man pages, but having something that gets me what I really need very quickly is important. Steps: 1. Use ag 2. If ag isn't present, try to install ag 3. If I can't install ag, then use grep or find, no big deal. ag > ack > grep/find
- burntsushi 7y ago> it also didn't provide as good support for filename searching Could you elaborate on this? Is it because you need to type more? If so, I'd suggest one of two things. 1) use `fd` for searching for files, which is dedicated to that purpose. 2) define `alias rgf="rg --files | rg"` (or similar) and use `rgf foo` just like you would use `ag -g foo`.
- JetSpiegel 7y agoripgrep > > > ag