You are not logged in.

#1 2023-06-22 11:53:04

thomasave
Member
Registered: 2018-12-28
Posts: 3

Zsh autocomplete of remote paths are not escaped correctly

Hello everyone,


I'm trying to use Zsh in combination with rsync or scp to copy files from a remote server to a local directory.
Some of these files have complicated paths, so I use tab completion to easily navigate to the correct paths, just like I would for a local directory structure.
This works for paths that don't have to be escaped, but many directories on my server contain spaces in their names.
When trying to autocomplete such paths, zsh escapes them twice instead of once, leading to paths that don't exist.

I have for instance a file "/home/server/Test Directory/file.txt", which I want to copy to my local client.
I can copy this correctly using:

rsync server:Test\ Directory/file.txt .

But zsh autocompletes this to:

rsync server:Test\\\ Directory/file.txt .

Which results in:

rsync: [sender] change_dir "/home/server/Test\ Directory" failed: No such file or directory (2).
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1861) [Receiver=3.2.7]
rsync: [Receiver] write error: Broken pipe (32)

How can I make sure that this first command would be generated by using the autocomplete instead of the second one?
A .zshrc file with only the following line can be used to replicate this issue:

autoload -Uz compinit && compinit

Thanks in advance!

Offline

#2 2023-06-22 12:12:43

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 74,325

Re: Zsh autocomplete of remote paths are not escaped correctly

The completion function is in /usr/share/zsh/functions/Completion/Unix/_rsync - did you try to just simply the file?

rsync 'server:Tes # press tab

Offline

#3 2023-06-22 12:23:24

thomasave
Member
Registered: 2018-12-28
Posts: 3

Re: Zsh autocomplete of remote paths are not escaped correctly

Thanks for the reply! Putting a single quote at the start does indeed result in only one backslash:

rsync 'server:Test\ Directory/file.txt' .

But now it is still escaped twice through the quotes, resulting in the same error as before.
I guess it is easier to later remove the two quotes then all the extra backslashes, but it's still not really optimal.

Offline

#4 2023-06-22 14:23:42

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 74,325

Re: Zsh autocomplete of remote paths are not escaped correctly

/usr/share/zsh/functions/Completion/Unix/_rsync uses /usr/share/zsh/functions/Completion/Unix/_remote_files, see whether the remote system pre-escapes the output:
https://www.zsh.org/mla/users/2018/msg00473.html

Offline

Board footer

Powered by FluxBB