Improved searching with The Silver Searcher(thechangelog.com)
thechangelog.com
Improved searching with The Silver Searcher
http://thechangelog.com/searching-improved-with-the-silver-searcher/
14 comments
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
dir="$1"
shift
# 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+"$@"}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:
[1] https://github.com/harthur/replace
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
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. :(
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 totalI use this to search only php files
ag --stats -G ".*\.php" SearchForThis
ag --stats -G ".*\.php" SearchForThis
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.
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.
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).
Now I can do
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.