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

Allow walking multiple root directories #4109

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

msabathier
Copy link

Hi,
I have been trying to search a file or directory with fzf on Windows on multiple drives.
I managed to do it by piping the output of Get-ChildItem cmdlet (slow) and then the output of fd (faster but not ideal).
It was not a satisfying solution to me so i started to look at the code of fzf and found a solution to this problem by using a comma separated list in the --walker-root argument.
I am not proficient in go so the implementation might not be what you are looking for, don't hesitate to guide me towards a solution that suits you.
Best regards,
Martin

@junegunn
Copy link
Owner

then the output of fd (faster but not ideal)

Can you explain why it felt not ideal? fd is a dedicated directory traversal program with much more versatility (notably .gitignore support). The built-in walker of fzf can be a good default for many users, but it isn't supposed to be, or tries to be, as good as dedicated external programs.

@msabathier
Copy link
Author

msabathier commented Nov 23, 2024

That was also my initial thought, but after a bit of testing, I found that the built-in walker was actually quite faster than fd, at least on Windows (maybe the piping is introducing some overhead ?).

Also when using fd, the pipe crashes if I select a result before fd has finished executing. This can probably be fixed but it led me to test other solutions first, one of which was this PR that I found was faster and more practical than using fd.

@junegunn
Copy link
Owner

/cc @charlievieth FYI

@charlievieth
Copy link
Contributor

charlievieth commented Nov 24, 2024

Despite being the author of fastwalk I actually use fd with fzf because I like colors (I actually pipe it through cfd which I wrote to perform an ANSII escape code aware sort on the output - god help me).

Regarding the performance of fd - it is generally quite fast. There was an issue from a few years ago about its performance when colorizing output (sharkdp/fd#720) which was resolved (so make sure you're up-to-date). Generally, fd and fastwalk will have the exact same performance (the performance of both is largely dictated by the filesystem), but fd can end up doing a bit more work than fastwalk since it may be colorizing the output (and there is overhead from having to pipe it to fzf).

The code changes around fastwalk look fine - though it might be nice if it could report which directory caused the issue. That said, , is a valid (though unusual) file path element (a,b is completely valid on POSIX systems) so this change would be incorrect if a filename with a , is passed to --walker-root.

Also, I currently don't have any plans to add native support for multiple search roots to fastwalk.

@junegunn
Copy link
Owner

@charlievieth Thanks for the comment.

That said, , is a valid (though unusual) file path element

I was also worried about the same thing and thought that we should take multiple arguments instead of a single comma-separated string.

See cff9d83

Some counter-points:

  • One may argue that it's inconsistent with --walker-skip
  • Although highly unlikely, if you have a directory whose name matches the name of an fzf option, it can be mistakenly recognized as an argument to --walker-root. e.g. --walker-root foo bar --reverse (and you have a directory named --reverse)

@msabathier
Copy link
Author

Thank you both for the informative comments !

I wasn't aware that , was a valid character in UNIX file paths and I tried to mimic the behaviour of other list-like arguments.

I remain at your disposal if you need anything.

@junegunn
Copy link
Owner

@msabathier Please review and test the last two commits I made on your branch.

@msabathier
Copy link
Author

I just reviewed and tested your changes and everything looks and works fine to me.

On a side note, i did a bit of performance testing and i found that fzf was on par with fd except when looking only for directories on Windows :

  • fzf took 6.2s on average.
    Measure-Command {fzf -f "" --walker=dir,hidden --walker-root=C:\}
  • fd took 10.0s on average.
    Measure-Command {fd -H -t d "" C:\}

If we pipe fd into fzf in interactive picker mode then fzf always wins because of the piping overhead.

@charlievieth
Copy link
Contributor

I was also worried about the same thing and thought that we should take multiple arguments instead of a single comma-separated string.

Makes sense to me.

On a side note, i did a bit of performance testing and i found that fzf was on par with fd except when looking only for directories on Windows

Nice and and thank you for taking the time to dig into this!

Looks good to me and thanks for the ping.

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

Successfully merging this pull request may close these issues.

3 participants