News for hackers. Stuff that matters.
Re:Don’t underestimate grep-based code scanning by fredley on Wednesday August 07, 2019 @10:09AM (#20634795)
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

Re:Don’t underestimate grep-based code scanning by Joeboy on Wednesday August 07, 2019 @11:50AM (#20635816)
Is there a reason to use ag rather than rg? afair the latter was a lot faster when I tried it (on ubuntu / intel).
Re:Don’t underestimate grep-based code scanning by dkarl on Wednesday August 07, 2019 @01:22PM (#20636812)
Same 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/

Re:Don’t underestimate grep-based code scanning by burntsushi on Wednesday August 07, 2019 @01:54PM (#20637107)
That table is quite out of date for ripgrep, which has added a number of features. See: https://github.com/beyondgrep/website/issues/97
Re:Don’t underestimate grep-based code scanning by dmix on Wednesday August 07, 2019 @03:59PM (#20638287)
Thanks 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)
Re:Don’t underestimate grep-based code scanning by wyldfire on Wednesday August 07, 2019 @01:53PM (#20637093)
Pretty 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.

Re:Don’t underestimate grep-based code scanning by burntsushi on Wednesday August 07, 2019 @02:01PM (#20637188)
Yes, 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.)
Re:Don’t underestimate grep-based code scanning by war1025 on Wednesday August 07, 2019 @11:48AM (#20635803)
I find `git grep` to be quite sufficient. A real pain when trying to look through code that isn't in git though.
Re:Don’t underestimate grep-based code scanning by Whoaa512 on Friday August 09, 2019 @01:25AM (#20651553)
you can just add `--no-index` to search in non-git repositories
Re:Don’t underestimate grep-based code scanning by hawski on Wednesday August 07, 2019 @10:41AM (#20635102)
It'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.
Re:Don’t underestimate grep-based code scanning by tigroferoce on Wednesday August 07, 2019 @10:48AM (#20635205)
I second ag too. Not because it's faster, but because it is developer-oriented so it has sane defaults for searching into code.
Re:Don’t underestimate grep-based code scanning by valbaca on Wednesday August 07, 2019 @01:13PM (#20636724)
+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/). 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

Re:Don’t underestimate grep-based code scanning by burntsushi on Wednesday August 07, 2019 @02:14PM (#20637315)
> 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`.

Re:Don’t underestimate grep-based code scanning by JetSpiegel on Wednesday August 07, 2019 @07:06PM (#20640141)
ripgrep > > > ag
Re:Don’t underestimate grep-based code scanning by justinmeiners on Wednesday August 07, 2019 @12:59PM (#20636549)
why not use a posix standard tool which is available everywhere? I appreciate the suggestion, but its worded a little strongly.