Fd: Is a ~/.ignore (or ~/.fdignore) file always looked at?

Created on 18 Sep 2019  路  11Comments  路  Source: sharkdp/fd

The README shows the following example:

> cat ~/.fdignore
/mnt/external-drive
*.bak
Note: fd also supports .ignore files that are used by other programs such as rg or ag.

On macOS I tried creating ~/.ignore and also a ~/.fdignore symlinked to ~/.ignore with the following in it as I'm trying to avoid mounted/network file systems when using fd from fzf:

.git
/Volumes
/net
/keybase

The expectation based on the README example if I just cd / && fd -t d keybase is to not return /keybase or /Volumes/Keybase but they are returned which makes me think that ~/.ignore or ~/.fdignore are not looked at.
If I'm explicit about using the ignore file fd --ignore-file ~/.ignore -t d keybase then it seems to work.

Not sure if this is a bug or expected behavior. It is very hard to tell as there's no documentation that lists the expected behavior, it's all very confusing.

I understand there have been a lot of discussions around ignore, it may be worth having a table of expected behavior then people can work from there when reporting issues.

documentation good first issue help wanted

Most helpful comment

We could also think about adding such a global .fdignore file. Maybe something like ~/.config/fd/ignore in analogy to ~/.config/git/ignore.

All 11 comments

Thank you for the feedback.

The README example is just wrong (or at least very misleading) and should be changed. A .fdignore or .ignore file will always just affect directories below it (just like .gitignore files). Putting /mnt/external-drive in .fdignore would therefore only ignore files in ~/mnt/external-drive (which is not what was originally intended with this example).

Not sure if this is a bug or expected behavior. It is very hard to tell as there's no documentation that lists the expected behavior, it's all very confusing.

Yes, it can be very confusing. The behavior is quite complex, but it is very well thought out (this is all part of the ignore crate/library which was designed for ripgrep). In principle, it is documented here: https://docs.rs/ignore/0.4.10/ignore/struct.WalkBuilder.html#ignore-rules

Here is how we set up the WalkBuilder in fd:
https://github.com/sharkdp/fd/blob/59c27baf0f1ed8ac441d316946ef37d28b23281b/src/walk.rs#L71-L103

If someone want's to spend some time to properly document this, it would be very appreciated.

OK, this helps, thank you. There is no way to have a global ignore file like ~/.gitignore_global for git.

What is the alternative? alias fd='fd --ignore-file ~/.fdignore_global ...'? If that's the answer, it would help to support a ~/.fd.conf file where default flags could be set for all apps that may be calling fd (like fzf), rather than an alias which only works in the shell.

We could also think about adding such a global .fdignore file. Maybe something like ~/.config/fd/ignore in analogy to ~/.config/git/ignore.

Ah, right. ~/.gitignore_global is not a built-in git thing, it has to be configured git config --global core.excludesfile ~/.gitignore_global It's in so many articles you start believing it is.

Maybe something like ~/.config/fd/ignore

Along the same lines, would you consider a ~/.config/fd/config (or defaults) for flags one may always want?

ah yes, I would have assumed that "git-ignored folders" would include my global "gitignore" file.

And the code:

.git_global(config.read_vcsignore)

looks like it could be supported

Ah, the directory that produced the unexpected result did not contain a .git directory. When I added that, the git-global ignore did work. Interesting.

We could also think about adding such a global .fdignore file. Maybe something like ~/.config/fd/ignore in analogy to ~/.config/git/ignore.

RigGrep supports a ~/.rgignore file for global ignores, and it is super handy.

I'd love to see that feature, is there any progress?

I don't think so. This should be rather easy to implement, though.

Implemented in #575 by @soedirgo.

Along the same lines, would you consider a ~/.config/fd/config (or defaults) for flags one may always want?

See #362

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Dietr1ch picture Dietr1ch  路  3Comments

lespea picture lespea  路  4Comments

mrzool picture mrzool  路  4Comments

kclevenger picture kclevenger  路  3Comments

sharkdp picture sharkdp  路  4Comments