Hacker News new | past | comments | ask | show | jobs | submit login
Improved searching with The Silver Searcher (thechangelog.com)
31 points by andrewpthorp on Feb 27, 2013 | hide | past | favorite | 14 comments

I've been using it for the past week (on my mac, homebrew is such a joy to use most of the time) and I absolutely love it. Before this I often had to type grep -lir "somestring" *, to recursively search in a project. Which would be often slow (reading huge binary files, ...) and is a handful to type. Admittedly I could've made an alias, but then I still would've had the binary file problem.

Now I can do

   ag "somestring"
And out comes beautifully colorized output in the blink of an eye telling me where and what. In short it comes with sane defaults for code searching and is faster than grep, what's not to like?

I fruitlessly tried ack once before and it never worked out for me, but this is staying in my toolbox.

The silver searcher, would recommend.

Not that I have anything against The Silver Searcher, but I've been using the following script I wrote for years, and it is even faster than ag from my very recent limited experience:

    #!/bin/sh -u


    # This doesn't work unless we have GNU find (for the -xtype option):
    gfind "$dir" \
	 \( -type f -or -xtype f \) \
	 \( -name "*.[ct]xx" \
	    -or -name "*.[CchH]" \
	    -or -name "*.py" \
	    -or -name "*.java" \
	    -or -name "*.scala" \
	    -or -name "*.pde" \
	    -or -name "*.js" \
	    -or -name "*.xml" \
	 \) \
	 -print0 \
      | xargs -0 egrep ${1+"$@"}

I wish ag were on linux boxes by default. Every time I instinctively try to search via ag and am denied I wince as I type in grep instead. :(

The Silver Searcher is very good for using the terminal as an IDE.

I have two aliases which I find very helpful.

- Search Obj-C files:

  alias ago='ag -G ".*\.(h|m)"'
- Search Ruby files:

  alias agr='ag -G ".*.rb"'
Also if you are looking for an alternative to sed don't miss replace[1].

[1] https://github.com/harthur/replace

From the github page (https://github.com/ggreer/the_silver_searcher):

  ack blahblahblah ~/code  6.59s user 1.94s system 99%  cpu 8.547 total

  ag  blahblahblah ~/code  1.39s user 1.81s system 229% cpu 1.396 total

I use both ag and ack interchangeably and one thing I wish is that ag would be 100% compatible with ack options. It'd be nice to just do a s/ack/ag and expect things to work.

I've been using ag for the past year or so, and it's great. One pain point remains the lack of Windows support, so I'm back to double-slow cygwin grep when on Windows.

I use this to search only php files

ag --stats -G ".*\.php" SearchForThis

How does "The Silver Searcher" translate to "ag"?

The chemical symbol for silver is Ag. It's a stretch, but it's short so I'm for it.

How does this differ from ack-grep?

It's faster than ack (according to their GitHub page), and it honors the .gitignore/.hgignore by default, which is a nice feature!

With Ack, I had to set up a bunch of --type-add lines to ~/.ackrc so that Ack wouldn't ignore e.g. SCSS files. ag searches every file by default, except for VCS files (e.g. .git/ and .hg) and files that are ignored by your VCS.

Ag's default behavior is way better, and less confusing to new users. Plus, it's faster.

It seems to be a bit faster than ack (which is just called 'ack', Debian the package is called 'ack-grep' to avoid conflicts).

Applications are open for YC Winter 2022

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact