tags:

views:

165

answers:

3

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
+3  A: 

ack is peculiar in that it doesn't have a blacklist of file types (actually just extensions) to ignore, but rather a whitelist of extensions 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.

Joachim Sauer
Great, thanks for the help! For anybody that's interested, the following page will give you a bit more info about adding unrecognized file types (like .haml) to ack: http://wiki.github.com/protocool/ack-tmbundle/recognizing-files
techpeace
The filetypes ack recognizes aren't just extensions. It will look at shebang lines as well. If you have a program "mywhatever" that starts "#!/usr/bin/perl", ack will know it's a Perl program.
Andy Lester
+2  A: 

ack --man states:

If you want ack to search every file, even ones that it always ignores like coredumps and backup files, use the "−u" switch.

and

Why does ack ignore unknown files by default? ack is designed by a programmer, for programmers, for searching large trees of code. Most codebases have a lot files in them which aren’t source files (like compiled object files, source control metadata, etc), and grep wastes a lot of time searching through all of those as well and returning matches from those files.

That’s why ack’s behavior of not searching things it doesn’t recognize is one of its greatest strengths: the speed you get from only searching the things that you want to be looking at.

EDIT: Also if you look at the source code, bak files are ignored.

nevets1219
Interesting, thanks! Didn't realize they had hard-coded in the .bak ignore.
techpeace
ack is optimized specifically for the common case of "find code in a tree of source code." In that common case, you want to ignore .bak files. It is NOT intended to be a general-purpose search tool, although you can make it that if you jump through hoops. Better to simply use grep if you need a general tool.
Andy Lester
+2  A: 

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.

Andy Lester
That is quite handy, as well... thanks!
techpeace