jethrokuan / fzf

Ef-🐟-ient fish keybindings for fzf
MIT License
861 stars 66 forks source link

TAB completion with directory names containing spaces #122

Open glykos opened 5 years ago

glykos commented 5 years ago

Using TAB completion with directories containing spaces in their names appears to be broken (?). I attach two screenshots with and without FZF_COMPLETE to illustrate the issue.

Without FZF TAB completion :

Without FZF TAB completion

With TAB completion, notice the missing part of the directory name :

With TAB completion, notice the missing part of the directory named 'VirtualBox VMs'

jethrokuan commented 5 years ago

This seems to only happen with the preview pane on... so the culprit is somewhere with this {1} and {2} splits, but I'm not sure how to resolve this atm.

https://github.com/jethrokuan/fzf/blob/91efdf70d3cec8b148afda4b80f97c2688df5ddc/functions/__fzf_complete.fish#L126

jswny commented 5 years ago

I'm having the same problem. In addition, while the preview pane doesn't actually show the parts of the directory name after the space, when you select a directory from it the whole directory including the space and whatever is after the space does get substituted into the command. However, the space is not escaped with a backslash and therefore the substituted directory is incorrect.

b6fd56c2e5f61591075c1fb5d5684de7

jswny commented 5 years ago

@jethrokuan Mind explaining what the --preview="fish\ '$file'\ __fzf_complete_preview\ '{1}'\ '{2..}'" part of this code does (I'm not super familiar with this syntax)? I'm trying to dig in and fix this problem. I've tested it out a bit and I've confirmed that this line is passing each part of the selected directory (split by spaces) to the preview pane function __fzf_complete_preview.

jethrokuan commented 5 years ago

Sorry for not getting back, have been pretty busy. I'm not familiar with this portion of the code itself, maybe @vic (who wrote these completion widgets) can help us out better?

autolyticus commented 4 years ago

I just ended up losing a bit of work due to this issue. I'm not using the preview pane at all. (set -U FZF_COMPLETE 0)

I had both a Library folder and a Calibre Library folder, and I wanted to delete the Calibre Library folder, but it resulted in

-> rm -rfv Cali<TAB>
...
-> rm -rfv Calibre Library
removed directory 'Library/'

I feel like the expected behaviour is for each line passed to fzf to be quoted.

jethrokuan commented 4 years ago

@reisub0 it's unfortunate that you've lost work because of that. I looked into this again, and am brought back to https://github.com/fish-shell/fish-shell/issues/3469. The crux of the issue is that for this completion widget to function correctly, the result of complete -C needs to be properly escaped where necessary.

complete -C returns in each line 2 items, tab-delimited. First item is the completion itself, and the second item is the description. For example, for me:

jethro@jethro ~/projects> complete -C"git"
git Executable, 2.2MB
git-receive-pack    Executable link, 2.2MB
git-shell   Executable, 1.2MB
git-upload-archive  Executable link, 2.2MB
git-upload-pack Executable, 1.3MB

I could parse each line, separate by tab, and escape the first item, but what about completions that may have tabs within them, e.g. file descriptors with tab characters? I'm hoping this is fixed upstream, but I'll add a caveat in the wiki page.

Koljasha commented 2 years ago

@jethrokuan for myself, I solved the problem as follows (It works fine for daily work): change two lines in functions/__fzf_complete.fish 100: commandline -t -- (string escape -n -- $r) 125: echo --preview-window=right:wrap --preview="fish\ '$file'\ __fzf_complete_preview\ '{1..}'"

glm4610 commented 2 years ago

@jethrokuan it seems like https://github.com/fish-shell/fish-shell/issues/3469 has been fixed and merged! (via https://github.com/fish-shell/fish-shell/pull/8645)

vergenzt commented 2 years ago

@Koljasha your workaround works great for me! Thanks for finding the spot. 🙂 To the group, would that approach work to outright resolve this issue? Or are there limitations it imposes that I'm not aware of? Seems like "escape fzf's completions" is basically exactly what's called for here. 🤔

simonm commented 1 year ago

Just moving over from zsh to fish and this is probably the last issue I have.

The workaround provided by @Koljasha fixes the tab complete for me. Preview is still borked with spaces. But, it seems that string escape is the answer.