2

i have ubuntu 14.04. and using ack-grep 2.12 to search for a text in files recursively inside a directory

I want to setup ack-grep options specific to the directory ~/workspace/project/ so that when i am at path ~/workspace/project and do ack 'mypattern' it search recursively in all child and grand-child directories,, and in all files recursively. and print the results. Further i have some child directories and also some grand child directories to ignore all files inside of them.

currently i am having a file .ackrc as ~/workspace/project/.ackrc

where i have written

  --ignore-directory=is:node_modules/
  --ignore-directory=is:public/bower_compoenents/

Now when i search ack-grep 'hello' it also searches in all the directories which i have instructed to IGNORE from .ackrc

Even using this pattern inside the .ackrc, it again searches in to be ignored directories. (PS : this works perfectly in the mac os x [EDIT : probably with an older version of ack])

  --ignore-dir=node_modules/
  --ignore-dir=public/bower_compoenents/

further none of these worked so far

--ignore-dir=public/bower_components --ignore-dir=is:public/bower_components

Am i doing anything wrong?

EDIT : looking for resolution to ignore searching in nested directory. (i do not want to supply any special option while executing ack-grep on command line)

codeofnode
  • 18,169
  • 29
  • 85
  • 142

2 Answers2

1

Quoting from the ack 2.12 manual:

--[no]ignore-dir=DIRNAME, --[no]ignore-directory=DIRNAME

Ignore directory (as CVS, .svn, etc are ignored). May be used multiple times to ignore multiple directories. For example, mason users may wish to include --ignore-dir=data. The --noignore-dir option allows users to search directories which would normally be ignored (perhaps to research the contents of .svn/props directories).

The DIRNAME must always be a simple directory name. Nested directories like foo/bar are NOT supported. You would need to specify --ignore-dir=foo and then no files from any foo directory are taken into account by ack unless given explicitly on the command line.

So it looks like you would need to drop the slashes and the nested directories.

Are you sure this works on your other machine? What version of ack is on that machine?

Community
  • 1
  • 1
Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
  • i have also used --ignore-dir=public/bower_components but still ack searches in public/bower_components directory. and on other machine, i don't remember the ack version. i just copied the .ackfile and pasted in my ubuntu machine. Dont have the mac machine right now. – codeofnode Dec 07 '14 at 17:03
  • in the second para of in the manual content.. what is the resolution to ignore nested directory. – codeofnode Dec 07 '14 at 17:05
  • `--ignore-dir=public/bower_components` is, as far as I can tell, just completely unsupported. And I don't know. You can `--ignore-dir=bower_components` but that will ignore that everywhere it appears I imagine. I don't know (from that bit of documentation specifically) how to make this work correctly. (The "explicitly on the command line" might be your best answer though. `--ignore-dir=public` and then manually put everything that isn't `bower_components` on the command line directly. Or something like that. – Etan Reisner Dec 07 '14 at 17:15
  • i do not want to supply any special option for nested directory. adding --ignore-dir=public ignores each and every directory inside public, whereas i only want to ignore one bower_components directory in public directory. is it possible to make any changes in .ackrc instead of inputing special option each and every time i execute ack-grep – codeofnode Dec 07 '14 at 17:24
  • You can `--ignore-dir=bower_components` assuming you only have the one `bower_components` directories. Otherwise, and without spending more time with the docs then I care to spend at the moment, the only solution I see is the command line one. This seems like it might just be a serious limitation of ack to me. – Etan Reisner Dec 07 '14 at 19:29
1

--ignore-dir=public/bower_compoenents should work if you invoke ack from the parent directory of "public". However, this may not work in Ubuntu's ack version if it is an old version (older than 1.93_02?). Download newer ack version (mine is 2.14).

See this thread:

Ignoring sub-directories in .ackrc

Community
  • 1
  • 1
Johnny Wong
  • 945
  • 9
  • 16
  • After looked at ack source code version 2.14, `--ignore-dir=public/bower_compoenents` will not work either, if you have any `--noignore-dir=...` option (in the command line or .ackrc). – Johnny Wong Jun 09 '16 at 09:35