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

TAB completion with directory names containing spaces #122

Open
glykos opened this issue Sep 13, 2019 · 10 comments
Open

TAB completion with directory names containing spaces #122

glykos opened this issue Sep 13, 2019 · 10 comments

Comments

@glykos
Copy link

glykos commented Sep 13, 2019

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
Copy link
Owner

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.

echo --with-nth=1 --preview-window=right:wrap --preview="fish\ '$file'\ __fzf_complete_preview\ '{1}'\ '{2..}'"

@jswny
Copy link

jswny commented Oct 2, 2019

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
Copy link

jswny commented Oct 25, 2019

@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
Copy link
Owner

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
Copy link

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.

autolyticus added a commit to autolyticus/dot that referenced this issue Dec 25, 2019
@jethrokuan
Copy link
Owner

@reisub0 it's unfortunate that you've lost work because of that. I looked into this again, and am brought back to fish-shell/fish-shell#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
Copy link

@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
Copy link

glm4610 commented Feb 18, 2022

@jethrokuan it seems like fish-shell/fish-shell#3469 has been fixed and merged! (via fish-shell/fish-shell#8645)

@vergenzt
Copy link

@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
Copy link

simonm commented Sep 9, 2023

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.

aurelilia added a commit to aurelilia/fzf that referenced this issue Sep 21, 2024
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

8 participants