Ripgrep: add flag to specify one or more additional ignore files

0

Hello,

This might be a feature borrowed from ag.

It is very convenient to have a global ~/.rgignore that applies everywhere. It would contain stuff like:

*~
*.lib
*.cdb
*.dm
*.tag
*.oa
*.png
*.db
*.state
*.SVM
*.dat
*.sdc
*.il
*.tr
*.Cat
*.cfg
*.info
*.stateScripts
*#*#
TAGS
GTAGS
GRTAGS
GPATH

Then, even if I am working in /proj/SOMEPRJ/ and if I have /proj/SOMEPRJ/.rgignore, then the SOMEPRJ specific .rgignore + ~/.rgignore, both will be respected.

That way I do not copy the common stuff in the .rgignore of all the projects. _Note that ~ (or /home/$USER) and /proj/SOMEPRJ/ do not share the same parent dir._

kaushalmodi picture kaushalmodi  ·  24 Sep 2016

Most helpful comment

8

No. The ignore code and the glob code are related but distinct. Sorry.

Refactoring the ignore code is pretty high on my list because I hope to get perf gains out of it.

I just got married. I'll get to this when I can.

BurntSushi picture BurntSushi  ·  11 Oct 2016

All comments

2

Hmm. Would you be opposed to this going in $XDG_CONFIG_HOME/ripgrep/ignore? That way, we won't need to specify any weird interaction between the current semantics, which are "obeys parent directory .ignore files," and the new semantics, which if we did what you suggested would be, "obeys parent directory unless $HOME/.ignore exists, in which case, it's used everywhere." $XDG_CONFIG_HOME feels a bit more right.

BurntSushi picture BurntSushi  ·  24 Sep 2016
0

I am on RHEL6.6 and echo $XDG_CONFIG_HOME returns

XDG_CONFIG_HOME: Undefined variable.

Also this is work machine.. so I don't have admin rights. Do we have an xdg alternative in that case?

kaushalmodi picture kaushalmodi  ·  24 Sep 2016
1

Sorry, by $XDG_CONFIG_HOME, I meant "follow the XDG basedir spec." Specifically, if XDG_CONFIG_HOME isn't set, then it defaults to $HOME/.config.

BurntSushi picture BurntSushi  ·  24 Sep 2016
0

Hmm, I symlinked $HOME/.config/ripgrep/ignore to ~/.agignore. I also tried few other symlink names. But none helped.. The files ignored in ~.agignore are still being searched.

km²~/.config/:ripgrep> lta                                                        
total 8.0K
drwxr-xr-x 28 kmodi users 4.0K Sep 24 00:48 ../
lrwxrwxrwx  1 kmodi users   21 Sep 24 00:52 .rpignore -> /home/kmodi/.agignore
lrwxrwxrwx  1 kmodi users   21 Sep 24 00:52 .ignore -> /home/kmodi/.agignore
lrwxrwxrwx  1 kmodi users   21 Sep 24 00:52 ignore -> /home/kmodi/.agignore
drwxr-xr-x  2 kmodi users 4.0K Sep 24 00:52 ./
km²~/.config/:ripgrep> pwd                                                             
/home/kmodi/.config/ripgrep
km²~/.config/:ripgrep> 
kaushalmodi picture kaushalmodi  ·  24 Sep 2016
1

Well, $HOME/.config/ripgrep/ignore functionality doesn't exist. I was proposing it and asking if it would satisfy your use case. :-)

BurntSushi picture BurntSushi  ·  24 Sep 2016
0

Ah OK, that would work as long as I can maintain just one common global ignore file :)

Thanks!

kaushalmodi picture kaushalmodi  ·  24 Sep 2016
0

Here's another idea to implement the same. I like it better because then I use an alias to have the complete rg configuration control.

How about having a switch named --ignore-file. Here's a spec suggestion for that:

--ignore-file FILE: Read the .ignore file FILE before reading the .ignore, .gitignore, etc. in the current or parent directories. Multiple --ignore-file flags may be used.

kaushalmodi picture kaushalmodi  ·  26 Sep 2016
0

When you say "Read the ignore file before reading .ignore .gitignore in current or parent directories," do you mean that --ignore-file takes precedence over them? (In contrast, I'd expect .ignore/.gitignore to take precedence over a global config file.)

BurntSushi picture BurntSushi  ·  26 Sep 2016
0

do you mean that --ignore-file takes precedence over them?

No, here was my thinking..

Let's use we did rg --ignore-file ~/.ignore foo and suppose we had:

$ cat ~/.ignore
*.log

Suppose we had a /proj and

$ cat /proj/.ignore
!imp.log

Then if ~/.ignore (FILE arg to --ignore-file) is read first, /proj/.ignore will be able to white-list some part out of the ignore set by the previously read file _if we are running rg --ignore-file ~/.ignore foo from the /proj directory._

So, _read first_ implies _open to be overridden_.

kaushalmodi picture kaushalmodi  ·  26 Sep 2016
0

@kaushalmodi Hmm, yes, I see, I think those semantics makes sense.

BurntSushi picture BurntSushi  ·  26 Sep 2016
0

FWIW the_silver_searcher uses --path-to-ignore SOMEPATH and the file name used is (as of 0.33.0) .ignore

davidosomething picture davidosomething  ·  26 Sep 2016
0

Allowing multiple --ignore-file becomes even more useful as I see an application where I can have a central .ignore file for the whole project (version controlled), and then users can add their specific .ignore files on top of that if they wish.

kaushalmodi picture kaushalmodi  ·  27 Sep 2016
0

@kaushalmodi I definitely like the idea of --ignore-file (allowing multiple uses) better than a global ignore file. If we just add that, does that satisfy your use case?

BurntSushi picture BurntSushi  ·  28 Sep 2016
0

If we just add that, does that satisfy your use case?

Absolutely! Then I need to simply add that to my alias and then it becomes as good as a global ignore file. What's even better is that I can have more than one global ignores.. one that is central to the whole project, others which could be user-specific.

kaushalmodi picture kaushalmodi  ·  28 Sep 2016
0

Perfect. Much easier to implement. Hopefully tonight. :-)

BurntSushi picture BurntSushi  ·  28 Sep 2016
0

Thanks! Just to confirm that they will have the lowest priority when compared with the ones in the current/parent directories as in my example above, correct?

kaushalmodi picture kaushalmodi  ·  28 Sep 2016
1

Yes. The terminology I'd like to use is "precedence." That is, ignore files specified via --ignore-file have a lower precedence than any other ignore file. That means a whitelisted pattern in an ignore file in a directory will override an ignore pattern in an --ignore-file.

BurntSushi picture BurntSushi  ·  28 Sep 2016
0

This is slightly trickier than I thought and probably exceeds my budget for middle-of-the-week work unfortunately. The issue is that every ignore file needs to interpret paths relative to _itself_ (these are the semantics of .gitignore, and frankly, nothing else really makes much sense), and current ignore code makes this a little tricky. I'm happy to hack this in because I have plans to overhaul the ignore code anyway, but it requires a bit more attention than I'm capable of right now.

BurntSushi picture BurntSushi  ·  29 Sep 2016
0

I hope that the overhaul in the globbing code now makes it possible to implement this.

kaushalmodi picture kaushalmodi  ·  11 Oct 2016
8

No. The ignore code and the glob code are related but distinct. Sorry.

Refactoring the ignore code is pretty high on my list because I hope to get perf gains out of it.

I just got married. I'll get to this when I can.

BurntSushi picture BurntSushi  ·  11 Oct 2016
0

I just got married. I'll get to this when I can.

Understood. Congratulations! :)

kaushalmodi picture kaushalmodi  ·  11 Oct 2016
2

Fixed in #202.

BurntSushi picture BurntSushi  ·  30 Oct 2016