Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ack|grep|whatnot special ignore folders pattern node_modules/dir/node_modules

I have recently discovered ack and ack -ir --ignore-dir={node_modules,dist,.git} <search-term> works great for most things but this

---node_modules/
---------------project1/
-----------------------node_modules/
---------------project2/
-----------------------node_modules/

I would like to search all files under the "root" node_modules and excluding all internal ones.

Note: if I run find . -type f | ack -v 'node_modules|.git|dist' under the root node_modules folder, I get a proper file list. this happen because find . gives out relative paths. Any way to feed this list to ack ?

like image 794
qballer Avatar asked Nov 13 '16 03:11

qballer


2 Answers

ack -i <search-term> ./node_modules/*

should do what you want. If you want to include hidden files and folders too, set shopt -s dotglob (assumes Bash) first.


Background information:

ack has many rules for ignoring files that you don't typically want to be searched built in.

As of at least version 2.14, this includes directories named .git and node_modules, at whatever level of the hierarchy (ack searches recursively by default, though you may add -r / -R / --recursive to make that explicit).
To see the complete list of directories / files that are ignored by default, run ack --dump.

By using globbing (pathname expansion) to let the shell expand pattern ./node_modules/* to a list of actual items inside ./node_modules, the ignore rule for node_modules is bypassed for those explicitly passed items.

like image 125
mklement0 Avatar answered Oct 21 '22 22:10

mklement0


node_modules is in the default --ignore-dir list in ack for javascript.

You can disable this using the --noignore-dir option to un-ignore node_modules.

  • directly on the command line:

    % ack --noignore-dir=node_modules -i <search-term>
    
  • in your .ackrc file:

    # in .ackrc
    --noignore-dir=node_modules
    

    which affects all searches:

    % ack -i <search-term>
    
like image 35
spazm Avatar answered Oct 22 '22 00:10

spazm