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

cd tab completion not working #872

Closed
3 of 15 tasks
tnguyen14 opened this issue Mar 13, 2017 · 43 comments
Closed
3 of 15 tasks

cd tab completion not working #872

tnguyen14 opened this issue Mar 13, 2017 · 43 comments

Comments

@tnguyen14
Copy link

tnguyen14 commented Mar 13, 2017

  • Category
    • fzf binary
    • fzf-tmux script
    • Key bindings
    • Completion
    • Vim
    • Neovim
    • Etc.
  • OS
    • Linux
    • Mac OS X
    • Windows
    • Windows Subsystem for Linux
    • Etc.
  • Shell
    • bash
    • zsh
    • fish

For some reason, cd <tab> is not auto-complete for me. I am running on a linux terminal X11-forwarded to a Windows machine.

fzf version is 0.16.6.

I have narrowed down the problem to these lines in shell/completion.bash:

# Directory
for cmd in $d_cmds; do
  _fzf_defc "$cmd" _fzf_dir_completion "-o nospace -o plusdirs"
done

Commenting them out gives me back the regular tab autocompletion behavior.

Please let me know if there's some way I could debug this further.

@vimkim
Copy link

vimkim commented Mar 13, 2017

You should cd **<tab> I guess? As ** being two literal * symbols.

@tnguyen14
Copy link
Author

I'm not sure what you mean. cd foo<tab> should match any file/ directory that starts with foo.

@vimkim
Copy link

vimkim commented Mar 14, 2017

Oh sorry, I guess I now understand what you meant. You are saying that the normal, default bash behavior of autocompletion does not work after installing FZF, right? That sounds strange. Is that only for cd, or for others as well such as vim foo<tab>?

@tnguyen14
Copy link
Author

@dqgthb yes that's exactly what I meant. It is very strange to me too.

@junegunn
Copy link
Owner

  • Is that only for cd, or for others as well such as vim foo?

  • What's the output of complete | grep cd$?

@tnguyen14
Copy link
Author

tnguyen14 commented Mar 20, 2017

It is for others as well, not just cd.

And the output for complete | grep cd$ is

complete -o nospace -F _fzf_dir_completion cd

@junegunn
Copy link
Owner

Hmm, it looks different than mine:

complete -o nospace -o plusdirs -F _fzf_dir_completion cd

Not sure why, bash version?

@tnguyen14
Copy link
Author

Hmm yeah I'm not sure - the one I have is bash version 4.3.42(1)

@junegunn
Copy link
Owner

What happens when you directly paste the command (complete -o nospace -o plusdirs -F _fzf_dir_completion cd) on your shell? Still no plusdirs?

@tnguyen14
Copy link
Author

tnguyen14 commented Mar 27, 2017 via email

@junegunn
Copy link
Owner

junegunn commented Mar 28, 2017

Then it's likely that you have some other plugin or configuration that are interfering with completion. Can you check if you can still reproduce the problem with a vanilla bashrc that only loads fzf and nothing else?

@tnguyen14
Copy link
Author

Here's what I just tried:

:; bash --noprofile --norc
# cd tab-completion works
:; source ~/.fzf.bash
# now tab-completion does not work
:; cat ~/.fzf.bash
# Setup fzf
# ---------
if [[ ! "$PATH" == */home/tnguyen14/.fzf/bin* ]]; then
  export PATH="$PATH:/home/tnguyen14/.fzf/bin"
fi

# Auto-completion
# ---------------
[[ $- == *i* ]] && source "/home/tnguyen14/.fzf/shell/completion.bash" 2> /dev/null

# Key bindings
# ------------
source "/home/tnguyen14/.fzf/shell/key-bindings.bash"

@junegunn
Copy link
Owner

I'm as clueless as you are. You're getting different results when you run complete -o nospace -o plusdirs -F _fzf_dir_completion cd manually and when it's run by completion.bash. 😕

@ezschemi
Copy link

I have this exact same issue since a few days.

As soon as this line is executed:

[[ $- == *i* ]] && source "$HOME/.fzf/shell/completion.bash" 2> /dev/null

tab completion stops working.

On an older system with bash 3.2.25 everything is still working.

When using putty from Windows to the Linux-system tab completion is still working.

This is the only bash plugin installed.

Running complete -o nospace -o plusdirs -F _fzf_dir_completion cd does not change anything, tab completion is not working.

System:
Red Hat Enterprise Linux 7.2
bash 4.2.46

@junegunn
Copy link
Owner

Hmm, I can't seem to reproduce the issue on Centos 7. I used this Dockerfile to set up the environment.

FROM centos:7

RUN yum -y update
RUN yum -y install git vim
RUN git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && \
    ~/.fzf/install --all
WORKDIR /usr/

@ezschemi
Copy link

I don't know what the differences between RHEL7.2 and Centos 7 (version?) are or how the Docker environment is different to a real installation.

fzf has just been uninstalled and reinstalled from scratch and the issue still exist.

What do you suggest for debugging completion.bash ?

@junegunn
Copy link
Owner

Hmm, I'm not sure if it's an issue of completion.bash.

What's the output of complete | grep cd$ ? Do you see complete -o dirnames -o nospace -F _fzf_dir_completion cd? (I recently changed plusdirs to dirnames, see #903).

@ezschemi
Copy link

Here you go:

> complete | grep cd$
complete -o nospace -F _fzf_dir_completion cd

this is with latest status on the master branch. Tab completion is not working.

@junegunn
Copy link
Owner

@ezschemi Does the output of complete | grep cd$ change when you manually execute the complete command?

complete -o dirnames -o nospace -F _fzf_dir_completion cd

If it doesn't, do you have any clue why it's not correctly applied to your system? Since I can't reproduce the problem locally, I need your assistance on this.

@ezschemi
Copy link

It does change:

> complete | grep cd$
complete -o nospace -F _fzf_dir_completion cd
02:36:38 /home/ezschemi
> complete -o dirnames -o nospace -F _fzf_dir_completion cd
02:37:19 /home/ezschemi
> complete | grep cd$
complete -o dirnames -o nospace -F _fzf_dir_completion cd

but tab completion still does not work.

Also note that tab completion does not work for commands like ls or cat, not just cd.

@junegunn
Copy link
Owner

junegunn commented Apr 28, 2017

Okay, so it does change when you do it manually, but it doesn't apply properly when it's called within completion.bash script? Strange, right? Can you help debugging the issue?

@ezschemi
Copy link

ezschemi commented May 2, 2017

Sure I can help. I have never debugged a bash script before though. What do you want me to do?

Let me see if I can quickly create a VM with RHEL 7.2 for you with remote access. Then you can debug it. Might be more efficient...

@aceforeverd
Copy link

I got unset tab complete not working.
Tested in Gentoo & Arch

@CeleritasCelery
Copy link

CeleritasCelery commented Sep 29, 2017

I am having the same issue as @ezschemi and everyone else here. when I run complete | ag cd$ I get the output

complete -o dirnames -o nospace -F _fzf_dir_completion cd

If I manually change it to complete -o bashdefault -o default -F _fzf_dir_completion cd it is fixed. For now that is going to be my workaround until this issue is resolved.

System:
Suse Linux
bash 4.4.0

@3N4N
Copy link

3N4N commented Jun 14, 2018

What is the update on this issue? I'm having same problem.

My bash version is 4.3.48.
I have tried with only this line
[ -f ~/.fzf.bash ] && source ~/.fzf.bash

The output of
complete | grep cd$ is complete -o nospace -F _fzf_dir_completion cd

Edit: I checked it with zsh v5.1.1 and it works well in zsh, but not in bash.

@3N4N
Copy link

3N4N commented Jun 15, 2018

@junegunn You need to look at the problem from this angle, maybe.

I found out that the problem is with tmux. When I'm outside tmux, inside neovim's terminal, tab-completion works normally. But when I'm inside tmux, it doesn't work. So, there must be something wrong with tmux.

@daveth
Copy link

daveth commented Jun 18, 2018

I'm on CentOS 7.5, having the exact same issues as mentioned above.
Tab-Completion seems to be affected by screen/tmux too, as @enanajmain is experiencing.

## new terminal, tab complete works
daev> complete | grep cd$
complete -o nospace -o plusdirs -F _fzf_dir_completion cd
daev> screen
## now tab-complete doesn't work
daev> complete | grep cd$
complete -o nospace -F _fzf_dir_completion cd
daev> complete -o nospace -o plusdirs -F _fzf_dir_completion cd
daev> complete | grep cd$
complete -o nospace -o plusdirs -F _fzf_dir_completion cd
## now tab complete works again

@3N4N
Copy link

3N4N commented Sep 25, 2018

Wow, I stopped using fzf for this issue and again installed it yesterday only to see that the bug is not fixed. What happened?

@097115
Copy link

097115 commented Sep 25, 2018

Just for the sake of it, just tried complete | grep cd$ under various versions of bash (3.2.53(1)-release and 4.4.23(1)-release), under screen and under tmux (with the latest fzf). The result was always the same:

~> complete | grep cd$
complete -o dirnames -o nospace -F _fzf_dir_completion cd

@junegunn
Copy link
Owner

@enanajmain

I stopped using fzf for this issue

That doesn't make sense to me as you can easily opt-out fuzzy completion during the installation process.

@3N4N
Copy link

3N4N commented Sep 27, 2018

you can easily opt-out fuzzy completion

I installed it with vim, so I didn't get the yes/no options that I got today when I installed it using git. I guess it was my bad.

@junegunn
Copy link
Owner

FYI, install script provides flags (see ./install --help) for non-interactive installation.

# All but fuzzy completion
./install --all --no-completion

# Just download the binary, and nothing else
./install --bin

@3N4N
Copy link

3N4N commented Sep 27, 2018

Ya, changed my init.vim. Thanks.

@jameshanlon
Copy link

I am experiencing this same issue running a vanilla .bashrc with only source $HOME/.fzf.bash.

Running on CentOS Linux release 7.5.1804 with GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu). Interestingly, the issue only occurs using Gnome Terminal (3.22.1) or Xfce terminal, in Xfce-4, and not via SSH or with XTerm.

Within Gnome terminal:

$ complete | grep cd$
complete -o nospace -o plusdirs -F _fzf_dir_completion cd

And setting explicitly:

complete -o dirnames -o nospace -F _fzf_dir_completion cd

Resolves the issue.

@ryanhuanli
Copy link

ryanhuanli commented Nov 4, 2019

I had same issue on bash, and finally figured out (at least in my case) it's related to the location fzf.bash get sourced, at the end of my default .bashrc, there are some stock completion like below erased fzf completion, after moving fzf bash source after this fix the issue.

.bashrc:

# source fzf.bash # was sourced here and not working

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

source fzf.bash # move to here works!

@jasonsyoung
Copy link

jasonsyoung commented Jan 22, 2020

So i figured out a fix for me, which is the opposite of the previous comment. Moving [ -f ~/.fzf.bash ] && source ~/.fzf.bash to the TOP of my .bashrc makes tab completion work, as well as Ctrl-R fuzzy finding for history.

I did some more digging. If I place it before the following, it works. If I place it after the following code, it does not work. This is the default code that comes on a standard debian .bashrc:

# 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 should note that I am using homebrew on linux, and have bash-completion@2 installed.

@richtong
Copy link

richtong commented Nov 4, 2020

OK running on Mac with homebrew and I discovered that for me, it has to go to the BOTTOM of ~/.bashrc. I think this is because there are some completions that are overwriting. A quick look at the bash.completion script makes it hard to figure out what is going on here, but basically the shortcuts seem to work anywhere, but the ** completion only works when it behind all the other completions. I have to have it after the bash completion installation.

This probably related to me installing bash_completion and not bash_completion@2 as described by https://docs.brew.sh/Shell-Completion, but for v1 on bash 5.x this does work

source "$(brew --prefix)/ext/bash_completion"
[ -f ~/.fzf.bash ] && source ~/.fzf.bash

And with the bash completion v2 it is the same thing, there line is somewhat different, but fzf has to come after it, you might want to add to the README

[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"

# fzf must come after this line, it appears to remove the cd completion
[ -f ~/.fzf.bash ] && source ~/.fzf.bash

@rayiik
Copy link

rayiik commented Nov 4, 2020

Hey just a note my cd complete reads as complete -o nospace -v -F _fzf_dir_completion cd and works however you might want to try switching the trigger from ** to ^^ or ~~ i believe your shell options (shopt) are causing bash ti interpret the ** as a glob pattern and not a trigger in-fact i was able to reproduce by set -o posix
Try set +o posix and that should fix your issue if im correct posix is changing the interpretation

—update tried changing the trigger and it didn't fix the issue but in still pretty sure its the posix flag still ill have a look at both then completion scripts this afternoon

@richtong
Copy link

richtong commented Nov 5, 2020 via email

@rayiik
Copy link

rayiik commented Nov 5, 2020

Hmm maybe its a separate issue i found then because the only way i could reproduce is (while working) set -o posix then it stopped working or does set spawn a new environment i had a script for a while that was on / off switch for environmental variables that broke fzf completion would unset some of the completion variables try adding an echo “$SHLVL” before and after both the fzf source and the bash complete source will help narrow down how the environment is being effected.

@junegunn
Copy link
Owner

junegunn commented Nov 5, 2020

@richtong

it has to go to the BOTTOM of ~/.bashrc. I think this is because there are some completions that are overwriting

That's correct. The fzf completion should be loaded at the end. The completion script of fzf is smart enough to keep the previous completion function as the fallback, but you can't expect the other scripts to do the same.

@rayiik Thanks for trying to help, but @richtong already found the right answer.

@richtong
Copy link

richtong commented Nov 6, 2020 via email

@boweeb
Copy link

boweeb commented Dec 18, 2020

FWIW, @rayiik gave the clue I needed. I was playing with various shopt glob settings and discovered nullglob will break completions. Handy for scripts but a bad idea for interactive login shells.

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

No branches or pull requests