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

`-prune` options #535

Open
std-odoo opened this issue Feb 13, 2020 · 9 comments
Open

`-prune` options #535

std-odoo opened this issue Feb 13, 2020 · 9 comments

Comments

@std-odoo
Copy link

@std-odoo std-odoo commented Feb 13, 2020

Is it possible to add an option -prune, to not explore sub-directories, when the current directory has been matched ? (like find -prune)

@sharkdp
Copy link
Owner

@sharkdp sharkdp commented Feb 16, 2020

Thank you for your feedback. Can you please give us some examples of actual (non-hypothetical) use cases for this?

@std-odoo
Copy link
Author

@std-odoo std-odoo commented Feb 17, 2020

@sharkdp Yes of course :)
I'm developing a package for sublime text, and I'm using your tool
https://github.com/Mister7F/Sublime-DirectoryFilter

I don't want to display a directory if one of the parent directory has matched the search :)

With the find tool, I can use the option prune, but as your tool is faster, I use it, and I prune the directory manually, in python.

@sharkdp
Copy link
Owner

@sharkdp sharkdp commented Feb 28, 2020

Ok, let's try to implement this as a new flag. We can hide it from the short -h help text.

@neuronull
Copy link

@neuronull neuronull commented Mar 12, 2020

Hello. I'd like to take this if its available?

@neuronull
Copy link

@neuronull neuronull commented Mar 12, 2020

Clarification on behavior: is prune meant to be a flag to operate on <pattern>?
for example:

$ tree
.
├── bar
│   └── zap
│       ├── foo
│       └── zig
└── foo
    ├── bar
    └── foo

$ fd foo
bar/zap/foo
foo
foo/foo

$ fd --prune foo
bar/zap/foo
foo
@std-odoo
Copy link
Author

@std-odoo std-odoo commented Mar 12, 2020

Yes :) it should work like this (the tool should stop to explore sub-directories when the current directories has matched)

neuronull added a commit to neuronull/fd that referenced this issue Mar 13, 2020
- Added --prune option which will not descend into directories
  that are a match on pattern.
- Added test to cover --prune option.
@sharkdp
Copy link
Owner

@sharkdp sharkdp commented Mar 28, 2020

@std-odoo Maybe you could help out with the design decisions in #546?

@jonathan-s
Copy link

@jonathan-s jonathan-s commented Jun 8, 2020

I'm happy to see that this is in the works!

@acheronfail
Copy link

@acheronfail acheronfail commented Jul 2, 2020

Thank you for your feedback. Can you please give us some examples of actual (non-hypothetical) use cases for this?

I have another use-case to share.
I tried to delete all the node_modules folders on my machine with fd, but found that due to needing a prune-like functionality I could not do this well, and so I had to fallback to using find.

For those unaware, a node_modules folder is a tree of packages, each with their own node_modules folders underneath. I wanted to delete all the node_modules folders in my home directory to save space, and fd was matching the subpackages as well, which means if I'd run -x rm -rf {} then it would have failed since a higher level directory could have been deleted before a lower level directory.
With prune this would not have been an issue.

Also, this is a common issue, common enough that there's a utility just for this: https://github.com/voidcosmos/npkill. But I would rather use fd for something like this, rather than a full-blown interactive UI.

🙂

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

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.