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

Fzf does not select path #4300

Open
5 of 10 tasks
danieleavitabile opened this issue Mar 6, 2025 · 6 comments
Open
5 of 10 tasks

Fzf does not select path #4300

danieleavitabile opened this issue Mar 6, 2025 · 6 comments

Comments

@danieleavitabile
Copy link

Checklist

  • I have read through the manual page (man fzf)
  • I have searched through the existing issues
  • For bug reports, I have checked if the bug is reproducible in the latest version of fzf

Output of fzf --version

0.60.3 (brew)

OS

  • Linux
  • macOS
  • Windows
  • Etc.

Shell

  • bash
  • zsh
  • fish

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?

@LangLangBart
Copy link
Contributor

From the video, it appears that everything works as expected until you make a selection. Since
nothing happens, it seems you cancel the operation.

If the observation is correct, I would assume that something is interfering with the
__fzf_generic_path_completion function.

fzf/shell/completion.zsh

Lines 166 to 178 in 26bcd0c

__fzf_comprun "$cmd_word" ${(Q)${(Z+n+)fzf_opts}} -q "$leftover" --walker "$walker" --walker-root="$dir" ${(Q)${(Z+n+)rest}} < /dev/tty
fi | while read -r item; do
item="${item%$suffix}$suffix"
echo -n -E "${(q)item} "
done
)
matches=${matches% }
if [ -n "$matches" ]; then
LBUFFER="$lbuf$matches$tail"
fi
zle reset-prompt
break
fi


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
the correct functioning of the fzf completion. One way to troubleshoot is to gradually remove parts
of your shell setup or make your setup public so we can identify where things go wrong.


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?

@danieleavitabile
Copy link
Author

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

_fzf_compgen_dir() {
  fd --type=d --hidden --exclude .git . "$1"
}

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

@LangLangBart
Copy link
Contributor

I have pinned down the issue to be related to the following lines in my .zshrc file

The _fzf_compgen_dir function gets evaluated and piped into fzf. The list with paths is shown correctly in your demo video, this suggests that fd works as expected, and the issue may lie somewhere else.

fzf/shell/completion.zsh

Lines 156 to 158 in 26bcd0c

if declare -f "$compgen" > /dev/null; then
eval "$compgen $(printf %q "$dir")" | __fzf_comprun "$cmd_word" ${(Q)${(Z+n+)fzf_opts}} -q "$leftover"
else

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>

@danieleavitabile
Copy link
Author

Hi @LangLangBart, yes, the issue is reproducible with the latest commands you give.

@LangLangBart
Copy link
Contributor

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.

  • zsh version is 5.9
  • fd version is 10.2.0
  • fzf version 0.60.3

Can you also enable execution tracing for the __fzf_generic_path_completion and share the output ?

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>

@danieleavitabile
Copy link
Author

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 /Users/daniele/.zsh/pure/

cd ~/**+__fzf_generic_path_completion:1> local base lbuf compgen fzf_opts suffix tail dir leftover matches
+__fzf_generic_path_completion:2> base='~/'
+__fzf_generic_path_completion:3> lbuf='cd '
+__fzf_generic_path_completion:4> compgen=_fzf_compgen_dir
+__fzf_generic_path_completion:5> fzf_opts=''
+__fzf_generic_path_completion:6> suffix=/
+__fzf_generic_path_completion:7> tail=''
+__fzf_generic_path_completion:9> setopt localoptions nonomatch
+__fzf_generic_path_completion:10> [[ '~/' = *\$\(* ]]
+__fzf_generic_path_completion:10> [[ '~/' = *\<\(* ]]
+__fzf_generic_path_completion:10> [[ '~/' = *\>\(* ]]
+__fzf_generic_path_completion:10> [[ '~/' = *:=* ]]
+__fzf_generic_path_completion:10> [[ '~/' = *`* ]]
+__fzf_generic_path_completion:13> eval 'base=~/'
+(eval):1> base=/Users/daniele/
+__fzf_generic_path_completion:14> [[ /Users/daniele/ = */* ]]
+__fzf_generic_path_completion:14> dir=/Users/daniele/
+__fzf_generic_path_completion:15> [ 1 ']'
+__fzf_generic_path_completion:16> [[ -z /Users/daniele/ || -d /Users/daniele/ ]]
+__fzf_generic_path_completion:17> leftover=''
+__fzf_generic_path_completion:18> leftover=''
+__fzf_generic_path_completion:19> [ -z /Users/daniele/ ']'
+__fzf_generic_path_completion:20> [ /Users/daniele/ '!=' / ']'
+__fzf_generic_path_completion:20> dir=/Users/daniele
+__fzf_generic_path_completion:21> matches=+__fzf_generic_path_completion:22> export FZF_DEFAULT_OPTS
+__fzf_generic_path_completion:23> FZF_DEFAULT_OPTS=+__fzf_generic_path_completion:23> __fzf_defaults '--reverse --scheme=path' ''
+__fzf_defaults:3> echo -E '--height 40% --min-height 20+ --bind=ctrl-z:ignore --reverse --scheme=path'
+__fzf_defaults:4> cat ''
+__fzf_defaults:5> echo -E ' '
+__fzf_generic_path_completion:23> FZF_DEFAULT_OPTS=$'--height 40% --min-height 20+ --bind=ctrl-z:ignore --reverse --scheme=path\n '
+__fzf_generic_path_completion:24> unset FZF_DEFAULT_COMMAND FZF_DEFAULT_OPTS_FILE
+__fzf_generic_path_completion:36> read -r item
+__fzf_generic_path_completion:25> declare -f _fzf_compgen_dir
+__fzf_generic_path_completion:26> __fzf_comprun cd -q ''
+__fzf_generic_path_completion:26> printf %q /Users/daniele
+__fzf_comprun:1> [[ "$(type _fzf_comprun 2>&1)" -regex-match function+__fzf_comprun:1> type _fzf_comprun
+__fzf_generic_path_completion:26> eval '_fzf_compgen_dir /Users/daniele'
+(eval):1> _fzf_compgen_dir /Users/daniele
+__fzf_comprun:1> [[ "$(type _fzf_comprun 2>&1)" -regex-match function ]]
+__fzf_comprun:3> [ -n '' ']'
+__fzf_comprun:11> shift
+_fzf_compgen_dir:1> fd '--type=d' --hidden --exclude .git . /Users/daniele
+__fzf_comprun:12> fzf -q ''
+__fzf_generic_path_completion:37> item=/Users/daniele/.zsh/pure/
+__fzf_generic_path_completion:38> echo -n -E '/Users/daniele/.zsh/pure/ '
+__fzf_generic_path_completion:36> read -r item 

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

No branches or pull requests

2 participants