Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is a ~/.ignore (or ~/.fdignore) file always looked at? #485

Closed
timkgh opened this issue Sep 18, 2019 · 11 comments
Closed

Is a ~/.ignore (or ~/.fdignore) file always looked at? #485

timkgh opened this issue Sep 18, 2019 · 11 comments

Comments

@timkgh
Copy link

timkgh commented Sep 18, 2019

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.

@sharkdp
Copy link
Owner

sharkdp commented Sep 18, 2019

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:

fd/src/walk.rs

Lines 71 to 103 in 59c27ba

let mut walker = WalkBuilder::new(first_path_buf.as_path());
walker
.hidden(config.ignore_hidden)
.ignore(config.read_fdignore)
.parents(config.read_fdignore || config.read_vcsignore)
.git_ignore(config.read_vcsignore)
.git_global(config.read_vcsignore)
.git_exclude(config.read_vcsignore)
.overrides(overrides)
.follow_links(config.follow_links)
.max_depth(config.max_depth);
if config.read_fdignore {
walker.add_custom_ignore_filename(".fdignore");
}
for ignore_file in &config.ignore_files {
let result = walker.add_ignore(ignore_file);
match result {
Some(ignore::Error::Partial(_)) => (),
Some(err) => {
print_error!(
"{}",
format!(
"Malformed pattern in custom ignore file '{}': {}.",
ignore_file.to_string_lossy(),
err.description()
)
);
}
None => (),
}
}

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

@timkgh
Copy link
Author

timkgh commented Sep 18, 2019

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.

@sharkdp
Copy link
Owner

sharkdp commented Sep 18, 2019

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

@timkgh
Copy link
Author

timkgh commented Sep 18, 2019

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.

@timkgh
Copy link
Author

timkgh commented Sep 18, 2019

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?

@kontrafiktion
Copy link

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

@kontrafiktion
Copy link

kontrafiktion commented Dec 7, 2019

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.

@robertfoss
Copy link

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.

@MarcinWieczorek
Copy link

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

@sharkdp
Copy link
Owner

sharkdp commented Apr 1, 2020

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

@sharkdp
Copy link
Owner

sharkdp commented May 18, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants