Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ack misses results (vs. grep)

Tags:

grep

ack

I'm sure I'm misunderstanding something about ack's file/directory ignore defaults, but perhaps somebody could shed some light on this for me:

mbuck$ grep logout -R app/views/ Binary file app/views/shared/._header.html.erb.bak.swp matches Binary file app/views/shared/._header.html.erb.swp matches app/views/shared/_header.html.erb.bak: <%= link_to logout_text, logout_path, { :title => logout_text, :class => 'login-menuitem' } %> mbuck$ ack logout app/views/ mbuck$ 

Whereas...

mbuck$ ack -u logout app/views/ Binary file app/views/shared/._header.html.erb.bak.swp matches Binary file app/views/shared/._header.html.erb.swp matches app/views/shared/_header.html.erb.bak 98:<%= link_to logout_text, logout_path, { :title => logout_text, :class => 'login-menuitem' } %> 

Simply calling ack without options can't find the result within a .bak file, but calling with the --unrestricted option can find the result. As far as I can tell, though, ack does not ignore .bak files by default.

UPDATE

Thanks to the helpful comments below, here are the new contents of my ~/.ackrc:

 --type-add=ruby=.haml,.rake --type-add=css=.less 
like image 977
techpeace Avatar asked Jun 14 '10 16:06

techpeace


2 Answers

ack is peculiar in that it doesn't have a blacklist of file types to ignore, but rather a whitelist of file types that it will search in.

To quote from the man page:

With no file selections, ack-grep only searches files of types that it recognizes. If you have a file called foo.wango, and ack-grep doesn't know what a .wango file is, ack-grep won't search it.

(Note that I'm using Ubuntu where the binary is called ack-grep due to a naming conflict)

ack --help-types will show a list of types your ack installation supports.

like image 94
Joachim Sauer Avatar answered Oct 02 '22 15:10

Joachim Sauer


If you are ever confused about what files ack will be searching, simply add the -f option. It will list all the files that it finds to be searchable.

like image 34
Andy Lester Avatar answered Oct 02 '22 15:10

Andy Lester