Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Bug#468654: zsh: rsync completion fails to complete remote paths with spaces



On Fri, Feb 29, 2008 at 03:04:14PM -0500, Adrian Irving-Beer wrote:
> If I have the following on host 'alpha':
> 
> 	/tmp/foo bar baz/foo
> 	/tmp/foo bar baz/bar
> 	/tmp/foo bar baz/baz
> 
> I can do this:
> 
> 	% rsync alpha:/tmp/foo<TAB>
> 	-->  % rsync alpha:/tmp/foo\\\ bar\\\ baz/
> 
> But I can't continue:
> 
> 	% rsync alpha:/tmp/foo\\\ bar\\\ baz/<TAB>
> 	--> no response
> 
> Tracing this, I found that it ran a failing 'ls' via ssh, something akin
> to this:
> 
> 	ssh -a -x alpha ls -d1FL "/tmp/foo bar baz/*"
> 
> This fails because the quoting only makes the argument appear as a
> single argument to 'ssh'; when ssh passes the command to the remote
> host, it comes out as trying to list three different files.
> 
> The solution is to double-quote the parameter, akin to this:
> 
> 	ssh -a -x alpha ls -d1FL "\"/tmp/foo bar baz/\"*"
> 
> I've attached a patch.  I'm no zsh expert, so it needs review -- I
> don't know if I've fixed one thing and broken another.  But it does
> seem to work for this situation.
> 
> --- /usr/share/zsh/functions/Completion/Unix/_rsync	2008-02-28 00:39:09.000000000 -0500
> +++ /usr/share/zsh-beta/functions/Completion/Unix/_rsync	2008-02-29 14:46:52.000000000 -0500
> @@ -58,7 +58,7 @@
>  elif compset -P 1 '*:'; then
>  
>    if zstyle -T ":completion:${curcontext}:files" remote-access; then
> -    remfiles=(${(M)${(f)"$(_call_program files ssh -a -x ${IPREFIX%:} ls -d1FL "${(Q)PREFIX%%[^./][^/]#}\*" 2>/dev/null)"}%%[^/]#(|/)})
> +    remfiles=(${(M)${(f)"$(_call_program files ssh -a -x ${IPREFIX%:} ls -d1FL "\"${(Q)PREFIX%%[^./][^/]#}\"\*" 2>/dev/null)"}%%[^/]#(|/)})
>      compset -P '*/'
>      compset -S '/*' || suf='remote file'

Maybe _rsync should get the same QIPREFIX check as _ssh and _git, or
maybe all three of these should be factored out into a helper function.



Messages sorted by: Reverse Date, Date, Thread, Author