-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Fzf does not select path #4300
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
Comments
From the video, it appears that everything works as expected until you make a selection. Since If the observation is correct, I would assume that something is interfering with the Lines 166 to 178 in 26bcd0c
Is the bug reproducible in a minimal zsh environment? command env -i "HOME=$HOME" "USER=$USER" "PATH=$PATH" "TERM=$TERM" zsh -f
source <(fzf --zsh)
cd ~/**<PRESS TAB> If the selection works as expected, that suggests something in your shell setup is interfering with Another way is to enable execution tracing by running: source <(fzf --zsh)
# Enable execution tracing. For more details, refer to 'man zshbuiltins'
typeset -ft fzf-completion
# Verbose Execution trace prompt (default: '+%N:%i> '). For more details, refer to 'man zshparam/zshmisc'
PS4=$'\n%B%F{0}+ %D{%T:%3.} %2N:%I%f%b '
cd ~/**<PRESS TAB> Please copy and paste the output here, which should look something like this: cd ~/**
+ 16:34:25:275 fzf-completion:478 local tokens prefix trigger tail matches lbuf d_cmds cursor_pos cmd_word
+ 16:34:25:275 fzf-completion:479 setopt localoptions noshwordsplit noksh_arrays noposixbuiltins
+ 16:34:25:275 fzf-completion:483 tokens=( cd '~/**' )
+ 16:34:25:275 fzf-completion:484 [ 2 -lt 1 ']'
+ 16:34:25:275 fzf-completion:490 trigger='**'
... Also, do you know if it was working previously and broke recently? |
Thank you @LangLangBart for helping out on this. I have pinned down the issue to be related to the following lines in my .zshrc file
I am using fd to generate the list for directory completion. Do you see any immediate problems with this? I understand now this may not be necessarily an fzf problem, but rather a problem at the interface, but any hint would help |
The Lines 156 to 158 in 26bcd0c
Is this issue reproducible if you execute the following commands? command env -i "HOME=$HOME" "USER=$USER" "PATH=$PATH" "TERM=$TERM" zsh -f
_fzf_compgen_dir() {
fd --type=d --hidden --exclude .git . "$1"
}
source <(fzf --zsh)
cd ~/**<PRESS TAB> |
Hi @LangLangBart, yes, the issue is reproducible with the latest commands you give. |
Thanks for confirming it, but I am unable to reproduce it on my end.
Can you also enable execution tracing for the command env -i "HOME=$HOME" "USER=$USER" "PATH=$PATH" "TERM=$TERM" zsh -f
_fzf_compgen_dir() {
fd --type=d --hidden --exclude .git . "$1"
}
source <(fzf --zsh)
typeset -ft __fzf_generic_path_completion
cd ~/**<PRESS TAB> |
Hi @LangLangBart I have the same versions of zsh, fd, and fzf. Here is the output you request (the last 3 lines are produced after I select the path
|
I get the same execution trace as you provided, except my
@junegunn, are you able to reproduce the issue reported by @danieleavitabile on your end? Does the issue still occur when you modify _fzf_compgen_dir() {
ls "$1"
} |
@LangLangBart Thanks for looking into this. With the steps you provided, I'm seeing a long delay (2 or 3 seconds most of the time, sometimes longer like 5 seconds) after
But it does finish in the end.
There is no delay if |
Thanks for testing it. Very likely. It's just odd that it stops instantly for me and returns my terminal prompt. time (fd --type=d --hidden --no-ignore . ~ | fzf --bind 'focus:accept')
/Users/paria/.dendron/
user=0.11s system=0.30s cpu=423% total=0.095 This adds a delay time (sleep 5 | fzf --bind 'start:reload:seq 5' --bind 'focus:accept')
1
user=0.01s system=0.02s cpu=0% total=5.007 Kill 'sleep' process time (sleep 5 | fzf --bind 'start:reload:seq 5; lsof -c sleep -t | xargs kill' --bind 'focus:accept')
1
user=0.02s system=0.03s cpu=83% total=0.057 |
I can explain. When fzf terminates, the standard output of fd is closed, thus fd can no longer write to it and gets "Broken pipe" which effectively causes it to stop. A workaround is to use a command substitution like so: fzf --bind 'start:reload:seq 5' --bind 'focus:accept' < <(sleep 5) However, So anyway, because of the "broken pipe" mechanism mentioned above, fd should normally stop as soon as it generates another output line. |
Okay, I realized that I was running fd 9.0.0, and the delay seems to have gotten smaller after I upgraded it to 10.2.0. EDIT: Hmm, nope. I'm still observing long delays (10 seconds) sometimes. But this just seems like an issue of fd, and there's not much we can do about it. |
I have also gone back to this and I also see this is a long, very long delay (orders of dozens of seconds and more) with fd 10.2.0 and fzf 0.60.3 |
Related comment: sharkdp/fd#1479 (comment) So you might close the issue as The built-in directory walker1 by Footnotes |
I was wondering if there was a way to work around the issue, like using command substitution like I mentioned above. However, interestingly, it doesn't help in this context, possibly due to the use of # Stops immediately
fzf --bind 'start:reload:seq 5' --bind 'focus:accept' < <(sleep 5)
# Takes 5 seconds to stop
eval "fzf --bind 'start:reload:seq 5' --bind 'focus:accept'" < <(sleep 5) (I remember fish had a similar problem with |
What if you place the --- a/shell/completion.zsh
+++ b/shell/completion.zsh
@@ -155,5 +155,5 @@ __fzf_generic_path_completion() {
unset FZF_DEFAULT_COMMAND FZF_DEFAULT_OPTS_FILE
if declare -f "$compgen" > /dev/null; then
- eval "$compgen $(printf %q "$dir")" | __fzf_comprun "$cmd_word" ${(Q)${(Z+n+)fzf_opts}} -q "$leftover"
+ __fzf_comprun "$cmd_word" ${(Q)${(Z+n+)fzf_opts}} -q "$leftover" < <(eval "$compgen $(printf %q "$dir")")
else
if [[ $compgen =~ dir ]]; then |
Well, that wasn't a great example. Anyway, I tried that version and it didn't help. You can easily reproduce the problem with this: command env -i "HOME=$HOME" "USER=$USER" "PATH=$PATH" "TERM=$TERM" zsh -f
_fzf_compgen_dir() {
echo 'hello'
sleep 10
echo 'world'
}
source shell/completion.zsh
typeset -ft __fzf_generic_path_completion
# Select 'hello'
cd **<TAB> Interestingly, # fzf finishes immediately once selection is made
fzf < <(_fzf_compgen_dir)
# _fzf waits for _fzf_compgen_dir to finish
_fzf() {
fzf
}
_fzf < <(_fzf_compgen_dir) |
That was helpful. Possible solution1 ?
--- a/shell/completion.zsh
+++ b/shell/completion.zsh
@@ -155,5 +155,10 @@ __fzf_generic_path_completion() {
unset FZF_DEFAULT_COMMAND FZF_DEFAULT_OPTS_FILE
if declare -f "$compgen" > /dev/null; then
- eval "$compgen $(printf %q "$dir")" | __fzf_comprun "$cmd_word" ${(Q)${(Z+n+)fzf_opts}} -q "$leftover"
+ (
+ eval "$compgen $(printf %q "$dir")" | {
+ __fzf_comprun "$cmd_word" ${(Q)${(Z+n+)fzf_opts}} -q "$leftover"
+ kill -PIPE 0
+ }
+ )
else
if [[ $compgen =~ dir ]]; then Footnotes |
@LangLangBart Wow, thanks, the patch works great with both the "sleep" example and the original fd command we discussed. Are there any concerns with it? |
It worked for me as well, and I didn't encounter any issues with it. I was just hesitant because Footnotes |
Checklist
man fzf
)Output of
fzf --version
0.60.3 (brew)
OS
Shell
Problem / Steps to reproduce
As you can see from this recording, when I invoke the ** shortcut, and I select a path, this path is not copied across
Screen.Recording.2025-03-06.at.09.04.45.mov
This happens in 3 different terminal emulators using zsh. Do you know how to solve this issue?
The text was updated successfully, but these errors were encountered: