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 there a way to ignore certain subdirectories? #721

Closed
hhmitchell opened this issue Jan 28, 2021 · 4 comments
Closed

Is there a way to ignore certain subdirectories? #721

hhmitchell opened this issue Jan 28, 2021 · 4 comments
Labels

Comments

@hhmitchell
Copy link

What version of fd are you using?
8.2.1

I am trying to use fd to list files in some set of directories, but excluding some.
Suppose I want to search in project1/foo/bar and project2/foo/bar, which have lots of subdirectories. I want to ignore everything under project1/foo/bar/baz, but do want to include everything in project2/foo/bar/baz.

This doesn't seem to work:
fd --exclude "project1/foo/bar/baz" . project1/foo/bar project2/foo/bar
Nothing gets filtered.

If I do:
fd --exclude "baz" . project1/foo/bar project2/foo/bar
this correctly excludes baz under project1/foo/bar, but also incorrectly excludes the one under project2/foo/bar.

Is there a way to accomplish this? Preferably with one command, though I am OK with multiples invocations if needed.

Thanks.

@sharkdp
Copy link
Owner

sharkdp commented Jan 29, 2021

Thank you for reporting this. I believe this is related to #374?

Is there a way to accomplish this? Preferably with one command, though I am OK with multiples invocations if needed.

If you are okay with multiple invocations, you can simply use this. Admittedly, it's not great:

fd --exclude "baz" . project1/foo/bar
fd . project2/foo/bar

It would also work if you don't specify the search paths directly:

fd --exclude "project1/foo/bar/baz" .

Obviously, this might include other search results under the current directory that you are not interested in. If there are not too many other folders, you could --exclude all of them.

Another idea would be to place the baz pattern in project1/foo/bar/.fdignore. In that case, you can simply run:

fd . project1/foo/bar project2/foo/bar

@hhmitchell
Copy link
Author

Thanks for the response. I'm not sure it's really related to #374 as that has more to do with the syntax of ignore files. In this case, I guess I was looking for a flag to do what .fdignore does (wasn't really clear how this worked until I experimented now).

There are hundreds of top-level project dirs with thousands of files each. I only care about a few of them, so not specifying search paths is not viable.
Creating a .fdignore under project1/foo/bar is feasible, but not clean as I can't commit that.

But having a .fdignore somewhere global that specifies project1/foo/bar/baz seems to work:
fd --ingore-file /tmp/.fdignore . project1/foo/bar project2/foo/bar
I can certainly work with that.

@sharkdp
Copy link
Owner

sharkdp commented Jan 30, 2021

Creating a .fdignore under project1/foo/bar is feasible, but not clean as I can't commit that.

I see why you wouldn't want that. An option might be to add .fdignore as an entry to .git/info/exclude, which only affects your copy of the repo. This way, you have a clean repository state and nobody else is affected.

@hhmitchell
Copy link
Author

Thanks for this info. We don't use git, but TIL what this folder does!

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

No branches or pull requests

2 participants