News for hackers. Stuff that matters.
Re:Ack - better than grep, a power search tool for programmers by pyre on Thursday December 03, 2009 @08:13PM (#975586)
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).
Re:Ack - better than grep, a power search tool for programmers by carbon8 on Thursday December 03, 2009 @11:56PM (#975831)
I'm pretty sure it's the same on debian.
Re:Ack - better than grep, a power search tool for programmers by ptn on Friday December 04, 2009 @10:18AM (#976453)
First thing that went to my .bashrc was:

alias ack='ack-grep'

Re:Ack - better than grep, a power search tool for programmers by sireat on Friday December 04, 2009 @10:33AM (#976485)
Correct, ack - Kanji code converter is the one I just installed by not reading HN posting first...
Re:Ack - better than grep, a power search tool for programmers by thwarted on Thursday December 03, 2009 @08:01PM (#975560)
Re:Ack - better than grep, a power search tool for programmers by aristus on Thursday December 03, 2009 @08:29PM (#975609)
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
Re:Ack - better than grep, a power search tool for programmers by dylanz on Thursday December 03, 2009 @08:12PM (#975582)
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'

Re:Ack - better than grep, a power search tool for programmers by dylanz on Thursday December 03, 2009 @08:15PM (#975589)
One day I'll grok the formatting for HN. Just not today obviously :/
Re:Ack - better than grep, a power search tool for programmers by basugasubaku on Thursday December 03, 2009 @08:19PM (#975595)
FWIW "grep --color -n" does the same thing.
Re:Ack - better than grep, a power search tool for programmers by dylanz on Thursday December 03, 2009 @08:24PM (#975603)
Ah, thank you! Can't believe I haven't been using the -n flag all this time. These flags don't do "exactly" the same thing as Ack, as Ack actually breaks it down by distinct sections, with newlines. It's a bit easier on the eyes.
Re:Ack - better than grep, a power search tool for programmers by mseebach on Friday December 04, 2009 @08:41AM (#976302)
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.
Re:Ack - better than grep, a power search tool for programmers by youngian on Friday December 04, 2009 @04:31PM (#977253)
The newest version of grep has --exclude-dir, which handles .svn folders just fine.
Re:Ack - better than grep, a power search tool for programmers by _sh on Thursday December 03, 2009 @10:49PM (#975758)
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.
Re:Ack - better than grep, a power search tool for programmers by oliveoil on Friday December 04, 2009 @03:33AM (#976016)
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).
Re:Ack - better than grep, a power search tool for programmers by pieter on Friday December 04, 2009 @03:56AM (#976032)
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.
Re:Ack - better than grep, a power search tool for programmers by boucher on Thursday December 03, 2009 @08:02PM (#975564)
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.
Re:Ack - better than grep, a power search tool for programmers by sparky on Thursday December 03, 2009 @08:22PM (#975599)
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!
Re:Ack - better than grep, a power search tool for programmers by frig on Friday December 04, 2009 @09:43AM (#976394)
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.
Re:Ack - better than grep, a power search tool for programmers by boucher on Thursday December 03, 2009 @09:10PM (#975657)
Thanks!
Re:Ack - better than grep, a power search tool for programmers by aidenn0 on Thursday December 03, 2009 @11:47PM (#975819)
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.
Re:Ack - better than grep, a power search tool for programmers by mgrouchy on Thursday December 03, 2009 @09:15PM (#975669)
The Ack Textmate bundle on the site is pretty awesome as well.
Re:Ack - better than grep, a power search tool for programmers by mark_h on Thursday December 03, 2009 @09:45PM (#975694)
For the emacs folk, I use this: http://repo.or.cz/w/ShellArchive.git?a=blob_plain;hb=HEAD;f=...

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

Re:Ack - better than grep, a power search tool for programmers by netghost on Friday December 04, 2009 @01:48PM (#976935)
I love the Textmate bundle. I actually extended it a bit so that you could filter for file types, which might be handy to some folks: http://github.com/adamsanderson/ack-tmbundle
Re:Ack - better than grep, a power search tool for programmers by parbo on Friday December 04, 2009 @04:51AM (#976082)
Is it significantly better than M-x rgrep in Emacs?
Re:Ack - better than grep, a power search tool for programmers by mmc on Friday December 04, 2009 @02:48PM (#977042)
See also http://www.rooijan.za.net/?q=ack_el - you can compare each from within emacs.
Re:Ack - better than grep, a power search tool for programmers by mseebach on Friday December 04, 2009 @08:39AM (#976299)
Yes.

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

Re:Ack - better than grep, a power search tool for programmers by d0mine on Friday December 04, 2009 @09:16AM (#976356)
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
Re:Ack - better than grep, a power search tool for programmers by spudlyo on Thursday December 03, 2009 @08:10PM (#975579)
Being able to use --output with your matched subexpressions is worth going through the trouble of installing it.
Re:Ack - better than grep, a power search tool for programmers by yu on Thursday December 03, 2009 @07:59PM (#975557)
Re:Ack - better than grep, a power search tool for programmers by thwarted on Thursday December 03, 2009 @08:06PM (#975573)
Fortunately, your search tool doesn't need to be written in the same language your project is.

That being said, performance comparisons would be interesting. Not necessarily from a "which is better" standpoint, but from a "what can these projects borrow from each other", assuming it's not a straight port.

Re:Ack - better than grep, a power search tool for programmers by aditya on Thursday December 03, 2009 @08:05PM (#975571)
And ruby has rak: http://rak.rubyforge.org/
Re:Ack - better than grep, a power search tool for programmers by Pistos2 on Thursday December 03, 2009 @11:37PM (#975803)
Before I switched to ack, I used glark. http://www.incava.org/projects/glark/
Re:Ack - better than grep, a power search tool for programmers by hesdeadjim on Thursday December 03, 2009 @07:53PM (#975552)
Love it and have used it for years, A++ would buy again!!