Improved searching with The Silver Searcher
thechangelog.com
thechangelog.com
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.
#!/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+"$@"}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]. 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 totalag --stats -G ".*\.php" SearchForThis
Ag's default behavior is way better, and less confusing to new users. Plus, it's faster.