lincheney / fzf-tab-completion

Tab completion using fzf
GNU General Public License v3.0
623 stars 40 forks source link

`scp`: file tree completion does not work #77

Closed przepompownia closed 1 year ago

przepompownia commented 1 year ago

Assuming that you have foo host configured in ~/.ssh/config and its identity added to an agent so ssh foo is enough to access the remote host. Type ssh foo: and try to complete possible home directory paths both with built-in and fzf-tab-completion.

For me only built-in completion works.

lincheney commented 1 year ago

Hello

I'm not able to reproduce this behaviour. Are you able to give more details on what does not work (it hangs, no results given, wrong results given etc) and what shell you are using.

I added the following to my ssh config

Host foo
   HostName 127.0.0.1

and both zsh and bash gave me the expected results when completiong scp foo: (bash with fzf-tab-completion listed no files, but so did bash with builtin completion). I also tried against another computer (ie not 127.0.0.1) which also worked.

przepompownia commented 1 year ago

@lincheney thanks for trying.

I see only Loading matches ... about 8 s then the dialog closes without results and I can try again.

. /usr/share/bash-completion/bash_completion
. "$(realpath "$(dirname ${BASH_SOURCE[0]})")/.src/external/fzf-tab-completion/bash/fzf-bash-completion.sh"
bind -x '"\t": fzf_bash_completion'
bind '"\es": menu-complete'
bind '"\eS": menu-complete-backward'

with

env -i -- SSH_AUTH_SOCK="$SSH_AUTH_SOCK" bash --rcfile ~/.bashrc-fzf-tab.sh

Alt-s (or Esc-s) work as expected for me. Doesn't matter if I use Tmux with Kitty or pure XTerm.

przepompownia commented 1 year ago

I'm not familiar with zsh. With

source /etc/default/locale
source "${HOME}/.src/external/fzf-tab-completion/zsh/fzf-zsh-completion.sh"
bindkey '^I' fzf_completion

I get No such widget `fzf_completion' with Tab. After entering source "${HOME}/.src/external/fzf-tab-completion/zsh/fzf-zsh-completion.sh" manually, I get fzf_completion:69: command not found: _main_complete. _main_complete seems to be not defined in this project. I have installed zsh in Debian Sid.

lincheney commented 1 year ago

Hello

I have pushed this https://github.com/lincheney/fzf-tab-completion/commit/428f350b86a43dd5d259295e9a695dc073cc1bdf, are you able to see if this fixes it for you? I am not confident though, as the behaviour I am seeing with scp does not seem quite the same as yours. Do you get the 8s delay only with the fzf completion?

przepompownia commented 1 year ago

Yes, I get this timeout only with fzf completion.

With 428f350b86a43dd5d259295e9a695dc073cc1bdf I see that file tree is completed correctly (I checked it remotely too) but the result replaces the whole word i.e. the host name and colon disappears (doesn't matter if I start directly after the colon or with some leading characters).

lincheney commented 1 year ago

the host name and colon disappears

If I am completing paths for scp, I am getting the same behaviour if I use the normal bash completion, so it is expected (if incorrect) behaviour in my case. Are you getting something different? Unfortunately I am not experiencing the timeout on my end. It may be something I will have to rely on you to debug.

lincheney commented 1 year ago

I am getting the same behaviour if I use the normal bash completion

ahh I actually it appears this is happening because I am overriding $COMP_WORDBREAKS in my bashrc I will see if I can fix this

przepompownia commented 1 year ago

Please look here: https://asciinema.org/a/fVMZLEVOTNArDAB0ccGf4U2Nw

lincheney commented 1 year ago

Yes, the code was not handling $COMP_WORDBREAKS properly. Can you try out https://github.com/lincheney/fzf-tab-completion/commit/da0e8ed66a36a5c1dabc247faa6a766f771809c4

przepompownia commented 1 year ago

but... it was after exec bash from the shell with the old library :grin: Maybe some environment was exported into the new shell.

On a fresh shell it seems to complete, but only if foo is an alias to localhost. I was close to closing this issue, but I see that results for some remote machine comes from the local machine.

Please test it for some remote host.

lincheney commented 1 year ago

ahhhh ok how about this https://github.com/lincheney/fzf-tab-completion/commit/9b056d8011a0d46cb60e700f8cf528aef00ababa 🤞

przepompownia commented 1 year ago

With https://github.com/lincheney/fzf-tab-completion/commit/9b056d8011a0d46cb60e700f8cf528aef00ababa I get the correct completion :tada:

Great thanks for the non-trivial work (as usual here)!