junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
63.89k stars 2.37k forks source link

directory completion not working on WSL Ubuntu & Debian #3633

Closed TheStarAlight closed 6 months ago

TheStarAlight commented 7 months ago

Info

Problem / Steps to reproduce

I use fzf on WSL Ubuntu, Debian, Manjaro and Termux (on Android), the completion.bash is placed under my home directory and I source it in .bash_aliases. I access WSL Ubuntu and Debian via Windows Terminal. On Manjaro and Termux the fzf functions properly. However, the file path completion is fine but the directory completion is not working by default on WSL Ubuntu and Debian. I tried the apt version (0.29) and the binary in release page (0.46.1) and both not worked. What's also strange is that when I source the completion script completion.bash manually in the terminal, the directory completion works! What's wrong with it?

In my .bash_aliases:

export FZF_COMPLETION_TRIGGER='-'
source ~/.fzf_completion.bash

removing export FZF_COMPLETION_TRIGGER='-' and cd ** cannot trigger directory completion as well.

The .fzf_completion.bash is extracted from the downloaded zipped file in the release page: fzf_completion.bash.txt

Thank you for help ! 🙏🏻

junegunn commented 7 months ago

By default they use these functions to generate the list:

So,

# This should work
_fzf_compgen_path .

# How about this? Do you see any error messages?
_fzf_compgen_dir .
TheStarAlight commented 7 months ago

@junegunn Thank you for your reply :D I ran these commands and both output available paths and seemed to work fine. But I got a clue: I source the completion.bash in .bash_aliases, which is invoked in .bashrc:

# the default ending of .bashrc in Ubuntu & Debian systems

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
  . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

I think maybe the bash completion conflicts with the fzf completion, so I changed their order by moving . ~/.bash_aliases to the very bottom of .bashrc file and the fzf just worked :) Are there any other people who also ran into this issue? I think this issue about the conflict between fzf and bash-completion should be mentioned in the instruction.

junegunn commented 6 months ago

Are there any other people who also ran into this issue?

Yes, there have been a few over the years.

I think this issue about the conflict between fzf and bash-completion should be mentioned in the instruction.

Any two completion scripts will conflict with each other because the one loaded later overrides the completions from the one loaded earlier. The completion script of fzf, however, tries hard to respect the existing ones, but yeah, you have to load fzf after the other ones. The installation script adds the source line to the bottom of the configuration file, so it should be fine until the user adds another completion script below it.

Anyway, I'll think about that. Thanks.