How do you exclude a specific file from ack (ack-grep)?

If you run ack --create-ackrc it will output a whole bunch of presets for common files like minified javascript, css and directories like node_modules and .git. Very useful!

Here's the minified js option:

# minified Javascript
--ignore-file=match:/[.-]min[.]js$/
--ignore-file=match:/[.]js[.]min$

And here's how to ignore a directory called foo:

--ignore-directory=is:foo

If you want to save this to .ackrc run

ack --create-ackrc >> ~/.ackrc

and then delete what you don't need from that file.

Also, you can create another .ackrc file in your project's root folder for project specific stuff. I put that in .gitignore so it doesn't clutter the repo.


To ignore a single file using ack 2.0, provide a filter spec to the --ignore-file flag:

--ignore-file=is:cljout.js


No, ack 1.x will not let you exclude a single file. In ack 2.0, you can. ack 2.0 was currently in its first alpha is now the current recommended version of ack.

As far as your specific case of the minified Javascript file, what version of ack are you using? ack 1.96 should ignore minified JavaScript based on extension. If the extension check doesn't work, you could probably hack ack itself, since it's a single Perl program. You can hack the is_searchable function.

In ack 2.0, we're looking at ignoring any line over, say, 500 characters because it's clearly not source code.

You may also want to join us on the ack-users mailing list. We're pretty responsive.

Tags:

Ack