Ack — Ignoring multiple directories without repeating the flag

14.1k views Asked by At

Is it possible to ignore multiple directories in Ack, without repeating the flag?

e.g. I know the following works (i.e. setting multiple flags):

ack --ignore-dir=install --ignore-dir=php 'teststring'

I was hoping that I could separate directories with commas, like I can do with the extensions as follows:

ack --ignore-file=ext:css,scss,orig 'teststring'

However, the following comma separated ignore flag doesn't work:

ack --ignore-dir=install,php 'textstring'

Is it possible to use some short-hand equivalent, so I don't have to repeatedly type out the --ignore-dir flag?

4

There are 4 answers

2
Birei On

One approach could be to select those directories to exclude with a regular expression in -G option complemented with the option --invert-file-match. Based in your question, something like the following:

ack -a -G 'install|php' --invert-file-match 'textstring' .
0
Andy Lester On

Since you're using ack 2, you can put --ignore-dir=install and --ignore-dir=php in a .ackrc file in the root of your project. Then, every ack invocation in that tree will use those flags.

3
Mandar Pathak On

It's actually similar to how you would specify the include patterns for grep:

ack <term> --ignore-dir={dir_a,dir_b}

However, This format does not work with a single directory. So

ack <term> --ignore-dir={log}

will not work.

1
Kaless1n On

So to ignore single directory use

ack <term> --ignore-dir=dir_a

and to ignore multiple directories use

ack <term> --ignore-dir={dir_a,dir_b}