svent/sift

Request: support a sift-specific ignore file

Deewiant opened this issue · 7 comments

ag supports .agignore files, which basically work similarly to .gitignore or .hgignore files but are used only by ag. This is useful for example if you have large auto-generated files in your repository (so you can't use sift's .gitignore functionality because you can't have the VCS ignore them) that are matched all too often by accident, resulting in sift outputting useless lines several kilobytes long. It'd be useful if sift had similar functionality.

svent commented

This is an interesting use case.
You could solve this with a small local sift config (.sift.conf) in that directory, e.g.:

{
    "ExcludeFiles": [
        "*.cpp",
        "*.pl"
    ]
}

But I understand that using something like .siftignore with the .gitignore syntax would be more convenient, I will look into this.

Good point, I forgot about local .sift.conf files. Unfortunately they're restricted to the current working directory. If .sift.conf were picked up from parent directories similarly to .gitignore it'd be a perfectly fine solution.

svent commented

Early versions only respected a .sift.conf in the current working directory, but since version 0.3.3 sift searches the parent directories for a .sift.conf file and uses that.
So it should work, please let me know if you have a case where it does not using the latest version.

Ah, I didn't spot that in the documentation. Using the ExcludeFiles option in a parent directory's .sift.conf indeed works.

But I can't figure out a way of excluding an entire directory or directories. I'd imagine ExcludePath is the way to go but for it to work for this use case, it would need to be applied relative to the location of the config file, similarly to .gitignore. For instance, if I want to exclude a directory repo/sub/dir with .gitignore I have a number of choices:

  1. /sub/dir in repo/.gitignore
  2. /dir in repo/sub/.gitignore
  3. sub/dir in repo/.gitignore, if I'm happy with excluding sub/dir at any level
  4. dir in repo/sub/.gitignore, if I'm happy with excluding dir at any level below sub/
  5. dir in repo/.gitignore, if I'm happy with excluding dir at any level

With a .sift.conf in a parent directory I can only replicate the fifth alternative, I think. Ideally something like .siftignore would allow for all of the above.

svent commented

I agree that something like .siftignore would be much more practical and flexible in such cases.
I will implement something like it - thanks for sharing your thoughts on this!

svent commented

@ggreer and @BurntSushi just suggested that search tools should use the same file for custom ignore patterns - I think that is a great idea (see BurntSushi/ripgrep#40 / https://news.ycombinator.com/item?id=12568822).
I will implement this as discussed here: add an option to process .ignore files and treat the content like gitignore patterns.
I'd suggest that .ignore has a higher precedence than .gitignore.

What about a config option to allow specifying name(s) for ignore files? That would cover @Deewiant 's use case, as well as .p4ignore, .cvsignore, etc. I'm confident that the syntax of .*ignore files is similar enough that the existing parse functionality would work well.

Something similar has been done by tar, which has options --exclude-vcs-ignores and --exclude-ignore=file.