ack|grep|whatnot special ignore folders pattern node_modules/dir/node_modules
Asked Answered
E

2

5

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 ?

Ernaline answered 13/11, 2016 at 3:59 Comment(0)
P
6
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.

Psychophysiology answered 13/11, 2016 at 4:35 Comment(0)
K
6

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>
    
Kameko answered 11/7, 2019 at 17:10 Comment(2)
I'm kind of answering the wrong question, but I'm'ma leave it here so I find this later....Kameko
If you want to specifically search in that directory, you can specify it, and then ack won't ignore it, like so: ack somestring node_modulesSagunto

© 2022 - 2024 — McMap. All rights reserved.