
Ack - better than grep, a power search tool for programmers - mustpax
http://betterthangrep.com/
======
pyre
Worth mentioning that there is another program in the Ubuntu repos called ack.
They've renamed this to ack-grep (don't use Debian so I don't know if the
naming convention was pulled in from Debian Unstable or added by the Ubuntu
devs).

~~~
carbon8
I'm pretty sure it's the same on debian.

------
thwarted
Previous discussion at

<http://news.ycombinator.com/item?id=223977>

<http://news.ycombinator.com/item?id=830522>

------
aristus
If you are interested, I've posted an interactive shell for ack (and grep)
here:

<http://github.com/aristus/ack-shell>

    
    
        $ acksh ack
    
        1) ./ack-shell/ack-shell
          2:   ## iack (interactive ack)
         15:   prompt = 'ack> '
         44:   cmdline[0] = 'ack'
     
        ack> open 1 44

------
dylanz
I've been using Ack for a while, and really like it. It saves a few
keystrokes, and gives you a nice (colored) output of the results with line
numbers as well:

> grep -r unicorn .

./config/unicorn/unicorn_build.rb: logger unicorn_logger

./config/unicorn/unicorn_build.rb: old_pid =
'/home/rails/xxxxx/current/tmp/pids/unicorn.pid.oldbin

./config/unicorn/unicorn_production.rb:
'/home/rails/xxxxx/current/tmp/pids/unicorn.pid.oldbin'

> ack unicorn

config/unicorn/unicorn_build.rb

10:# logger unicorn_logger

14:# old_pid = '/home/rails/xxxxx/current/tmp/pids/unicorn.pid.oldbin'

config/unicorn/unicorn_production.rb

15:# '/home/rails/xxxxx/current/tmp/pids/unicorn.pid.oldbin'

~~~
basugasubaku
FWIW "grep --color -n" does the same thing.

~~~
mseebach
Not if you're using SVN. Or if someone stuck a 24MB SQL data-dump with
extended inserts somewhere, that has the word "unicorn" in it.

~~~
youngian
The newest version of grep has --exclude-dir, which handles .svn folders just
fine.

------
_sh
A nice alternative to my decidedly low-tech approach:

    
    
      (in ~/.zshrc)
      # 'ff' command -- find string in files with a specified suffix
      ff() {
        [[ -n $1 && -n $2 ]] || {
          echo "Usage $0 [suffix] [string]"
          echo "Where"
          echo "  suffix  file suffix (without wildcards)"
          echo "  string  string to search for (quote if spaces)"
          return
        }
        find . -name \*$1 -exec grep -Hn $2 "{}" \; | less -RFX
      }
    

Has colorized output, and only pages (with less) when there is more than one
page to show.

------
oliveoil
The time I sometimes lose reading HN pays off when I find stuff like this. BTW
the type heuristics is good enough to look inside of files to determine the
type: doing 'ack --python pattern' WILL DO look into python files that have no
extension (like the toplevel module for instance).

------
pieter
I just use 'git grep' to only grep in tracked files. It's worthwhile to learn
that tool, for example to learn how you can grep in older revisions.

------
boucher
How does one add a custom type to ack and get it to stick? Per the man page, I
tried:

    
    
         ack --type-set objj=.j
    

Doesn't work. I can append that to a query:

    
    
         ack CPWindowController --type-set objj=".j"
    

And it will search .j files for CPWindowController, but then it immediately
forgets .j and the objj type.

~~~
sparky
Create a .ackrc file in your home directory. For you, it will contain:

    
    
      --type-set
      objj=.j
    

I found this on the ack-grep man-page in Ubuntu. You can set the ACKRC
environment variable to give it a different directory (besides ~) to search
for your .ackrc. Each line of the .ackrc is a command-line arg that will be
prepended to any specified arguments every time you run ack-grep. If you don't
want those arguments for a particular query, pass the --noenv flag to ignore
the .ackrc. HTH!

~~~
frig
Just something I had a hard time figuring out and seems poorly documented:

    
    
        --type-set=scala=.scala # works in .ackrc
        --type-set scala=.scala # doesn't work in .ackrc
    

...despite the version with one equals being correct command-line sequence.
Only seems to matter if you want each flag on a single line in your .ackrc
file. Might not be true for everyone.

------
aidenn0
I have a wrapper around find that does things like filter out .svn
directories. I sometimes use ack for simple searches, but find/xargs/grep
together are faster and more explicit in my experience.

------
mgrouchy
The Ack Textmate bundle on the site is pretty awesome as well.

~~~
mark_h
For the emacs folk, I use this:
[http://repo.or.cz/w/ShellArchive.git?a=blob_plain;hb=HEAD;f=...](http://repo.or.cz/w/ShellArchive.git?a=blob_plain;hb=HEAD;f=ack.el)

But there's also (last I looked, may be more now):
<http://www.rooijan.za.net/?q=ack_el>

------
parbo
Is it significantly better than M-x rgrep in Emacs?

~~~
mseebach
Yes.

(M-x rgrep in Emacs == grep -r everywhere else)

~~~
d0mine
Not quite.

Emacs' _rgrep DIR PATTERN REGEX_ translates to

    
    
      find DIR \( -path \*/SCCS -o -path \*/RCS -o -path \*/CVS \
      -o -path \*/MCVS -o -path \*/.svn -o -path \*/.git \
      -o -path \*/.hg -o -path \*/.bzr -o -path \*/_MTN \
      -o -path \*/_darcs -o -path \*/\{arch\} \) -prune \
      -o  -type f \( -name PATTERN \) -print0 \
      | xargs -0 -e grep -i -nH -e REGEX

------
spudlyo
Being able to use --output with your matched subexpressions is worth going
through the trouble of installing it.

------
yu
python has grin <http://pypi.python.org/pypi/grin>

~~~
aditya
And ruby has rak: <http://rak.rubyforge.org/>

~~~
Pistos2
Before I switched to ack, I used glark.
<http://www.incava.org/projects/glark/>

------
hesdeadjim
Love it and have used it for years, A++ would buy again!!

