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

Global absolute paths in ignore file? #1150

Closed
tjex opened this issue Oct 29, 2022 · 4 comments
Closed

Global absolute paths in ignore file? #1150

tjex opened this issue Oct 29, 2022 · 4 comments
Labels

Comments

@tjex
Copy link

tjex commented Oct 29, 2022

What version of fd are you using?
8.4.0

I'm setting up the ignore file in .config/fd/.
I want to exclude a specific folder that is in my home directory.
My experience so far is that the dir paths set in ignore are relative to where fd is being executed.

Is there then a way to exclude a specific folder, no matter how many levels above the folder I am?
Ideally it would be great to set /Users/tillman/foo/ or ~/foo/ in the ignore file and have that file excluded no matter where I am in my machine.

Or is the only way to set:

tillman/foo/
/Users/tillman/foo/
etc
@tjex tjex added the question label Oct 29, 2022
@tmccombs
Copy link
Collaborator

I don't believe there is currently a way to do that, although I do think the ability to do so would be valuable.

Too potential hurdles are

  1. What should the syntax be? The most straightforward way would be to treat rules starting with / to be absolute instead of relative to the run directory. But that would definitely be backwards incompatible, and I'm not entirely sure how that would work on windows.
  2. I'm pretty sure this would require a change to the upstream ignore crate (also used by ripgrep) or at least some creative design to work around how it handles global ignore files (perhaps this issue would be better resolved upstream?)

@tjex
Copy link
Author

tjex commented Dec 3, 2022

I'm not yet knowledgeable enough to have much valuable input... But perhaps there could be an integration with the global gitignore file. Or a check how many levels deep fd is being executed from, and then referencing all ignore paths, but taking into consideration only the ignore paths that are deeper than it's current position in the system (as those would then be the only valid ones)...

Probably a lot wrong with those suggestions, but didn't want to just thow my hands up with no ideas...

@tmccombs
Copy link
Collaborator

tmccombs commented Dec 5, 2022

First of all, would putting an .fdignore file in your home directory specified the given subdirectory should be ignored be an option?

Secondly, from #763 (comment), I suspect that if you passed --absolute-path then the absolute patterns would work. That is due to some, uh, unexpected behavior of the ignore library though.

Finally, for parsing ignore files, and the logic for determining which files to ignore, fd uses a third party library called ignore (which is also used by ripgrep). You suggestions don't really get around the fact that that library doesn't support absolute path matching, so we would need to do one of the following: get a change merged into the upstream project (see BurntSushi/ripgrep#2366), fork the project and make a change, replace the library with something else, or find some creative way to work around the limitations of the library.

There might be a way to do that last one. Since, it seems to work if you pass --absolute-path, maybe if we always passed in the absolute path for the search path, and then made it relative again when displaying it, it could work. But, and it's a big but, I suspect this could have some unintended side effects, and would be surprised if it didn't hurt performance.

@tjex
Copy link
Author

tjex commented Dec 12, 2022

The issue is that the paths in .fdignore are interpreted as having their root at the current working directory from where fd is being invoked. This means that I'm never just ignoring the folder I want to ignore. I'm potentially ignoring folders that I do not want to ignore.

eg.
Documents is a folder in my home folder that I have no interest in.
But it's fairly likely that I work in a directory at some point that also as a Documents folder, which I do not want to ignore.

I will have a look into some of your other suggestions. Thanks!

But yes, for future readers, the issue linked above and here give the rest of needed context and show's that it's not something easily achievable / built in.

@tjex tjex closed this as completed Dec 12, 2022
@tjex tjex reopened this Dec 12, 2022
@tjex tjex closed this as completed Dec 12, 2022
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