Fd: Ignore file is ignored

Created on 27 May 2020  ยท  12Comments  ยท  Source: sharkdp/fd

Describe the bug you encountered:
I'm using the following command to list every file in my home directory from any other directory:

fd . ~ --type f --hidden

idk if this is the right way to do it, but it's the only one that worked after many tries. The problem is that this ignores my ignore file in ~/.config/fd/ignore, as I can see by

$ fd . ~ --type f --hidden | wc -l
72782
$ fd --type f --hidden | wc -l
4665

Describe what you expected to happen:
The ignore file is respected.

What version of fd are you using?
fd 8.1.0

Which operating system / distribution are you on?
macOS Catalina 10.15.4.

bug duplicate

All 12 comments

@n0ibe I got bit by this as well, turns out I'm using version 8.0.

Try to check the version you're using, if it's below version 8.1.1 you should upgrade first and report back if it still exhibiting the same issue

@n0ibe Thank you for reporting this. Maybe @soedirgo could have a look at this?

@thisguychris the report says "fd 8.1.0". This is the version that included the "global ignore file" feature, so it should work. It will definitely not work on 8.0.

I'm using version 8.1.1 now and the issue is still present. @sharkdp Btw, is that the right way to list every file in my home directory from another directory?

@n0ibe Thank you for reporting this. Maybe @soedirgo could have a look at this?

@thisguychris the report says "fd 8.1.0". This is the version that included the "global ignore file" feature, so it should work. It will definitely not work on 8.0.

whoops my bad, sorry, I had a tunnel vision there @sharkdp โœŒ๐Ÿป

Hmm, I'm not sure if I understand your problem. Can you give me more information? E.g.:

  • The contents of your ignore file (or at least the patterns that didn't get respected)
  • The files that didn't get ignored
  • Where you execute fd --type f --hidden | wc -l from

It'd help if you can provide a simple & minimal file hierarchy that demonstrates the problem.

Btw, is that the right way to list every file in my home directory from another directory?

Yup, this should be the right way to do it as per fd's error when you do fd ~.

My ignore file is

/Library/*
!/Library/texmf/
/.cache/*
/.dropbox/*
/Dropbox/.dropbox.cache/*

and it's in ~/.config/fd/ignore. None of the files inside those folders were ignored. I executed both fd . ~ --type f --hidden | wc -l and fd --type f --hidden | wc -l from my home directory.

It'd help if you can provide a simple & minimal file hierarchy that demonstrates the problem.

What do you mean exactly?

What do you mean exactly?

I meant this, but nevermind that, I get your problem now. This is how I understand fd works:

Let's say I have this as my home directory:

> tree ~
/Users/n0ibe
โ””โ”€โ”€ foo

When I execute fd without a path argument (~ in your example), it lists the entries relative to the current working directory:

> fd
foo

But when I execute it with a path argument, whether relative or absolute, entries are appended to it (note that fd . ~ is equivalent to fd . /Users/n0ibe):

> fd . ~
/Users/n0ibe/foo

This means the ignore pattern /foo will not ignore /Users/n0ibe/foo. Instead, you want **/foo, or if you only want to ignore that particular path, /Users/n0ibe/foo. In your case, you want your ignore file to be:

> cat ~/.config/fd/ignore
/Users/n0ibe/Library/*
!/Users/n0ibe/Library/texmf/
/Users/n0ibe/.cache/*
/Users/n0ibe/.dropbox/*
/Users/n0ibe/Dropbox/.dropbox.cache/*

Note that this doesn't work for, say, fd . / (you have to use **/Library/*, etc.). Also, it no longer works without pattern/path arguments (you have to use the -a/--absolute-path flag).

But when I execute it with a path argument, whether relative or absolute, entries are appended to it

that is actually a bug in the ignore crate. See https://github.com/BurntSushi/ripgrep/issues/829

that is actually a bug in the ignore crate. See BurntSushi/ripgrep#829

I'm not sure if that's relevant here. Are you referring to this? I don't know if it works with .gitignore files, but the behavior shown so far isn't unexpected to me (or maybe I'm fooling myself):

> tree
.
โ””โ”€โ”€ a
    โ””โ”€โ”€ b
        โ””โ”€โ”€ c

> cat ~/.config/fd/ignore
<project root>/a/b/c

> fd c
a/b/c

> fd c a
a/b/c

> fd --absolute-path c

> fd --absolute-path c a

I expect passing a path argument to fd to act the same as running fd from inside that path (but with relative paths from the working directory). I guess with a global ignore file it's a little less clear what the root directory should be.

@tmccombs Do you think this should be closed (as a duplicate)? Or is there anything that should be done?

I think it can be closed as a duplicate.

Was this page helpful?
0 / 5 - 0 ratings