5 ms·
Ack - better than grep, a power search tool for programmers
- hesdeadjim 17y agoLove it and have used it for years, A++ would buy again!!
- yu 17y agopython has grin http://pypi.python.org/pypi/grin http://pypi.python.org/pypi/grin
- aditya 17y agoAnd ruby has rak: http://rak.rubyforge.org/ http://rak.rubyforge.org/
- Pistos2 17y agoBefore I switched to ack, I used glark. http://www.incava.org/projects/glark/ http://www.incava.org/projects/glark/
- deleted 17y ago[deleted]
- thwarted 17y agoFortunately, 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.
- thwarted 17y agoPrevious discussion at http://news.ycombinator.com/item?id=223977 http://news.ycombinator.com/item?id=223977 http://news.ycombinator.com/item?id=830522 http://news.ycombinator.com/item?id=830522
- boucher 17y agoHow 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 17y agoCreate 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!
- boucher 17y agoThanks!
- frig 17y agoJust 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.
- deleted 17y ago[deleted]
- spudlyo 17y agoBeing able to use --output with your matched subexpressions is worth going through the trouble of installing it.
- dylanz 17y agoI'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'
- dylanz 17y agoOne day I'll grok the formatting for HN. Just not today obviously :/
- basugasubaku 17y agoFWIW "grep --color -n" does the same thing.
- dylanz 17y agoAh, 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.
- mseebach 17y agoNot 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 17y agoThe newest version of grep has --exclude-dir, which handles .svn folders just fine.
- pyre 17y agoWorth 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).
- aristus 17y agoIf you are interested, I've posted an interactive shell for ack (and grep) here: http://github.com/aristus/ack-shell 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
- mgrouchy 17y agoThe Ack Textmate bundle on the site is pretty awesome as well.
- mark_h 17y agoFor the emacs folk, I use this: http://repo.or.cz/w/ShellArchive.git?a=blob_plain;hb=HEAD;f=ack.el 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 http://www.rooijan.za.net/?q=ack_el
- netghost 17y agoI 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 http://github.com/adamsanderson/ack-tmbundle
- _sh 17y agoA 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.
- aidenn0 17y agoI 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.
- oliveoil 17y agoThe 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 17y agoI 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.
- parbo 17y agoIs it significantly better than M-x rgrep in Emacs?
- mseebach 17y agoYes. (M-x rgrep in Emacs == grep -r everywhere else)
- d0mine 17y agoNot 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
- mmc 17y agoSee also http://www.rooijan.za.net/?q=ack_el http://www.rooijan.za.net/?q=ack_el - you can compare each from within emacs.