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

Re: A cute bug involving aliases and _remote_files



On Tue, 2019-02-26 at 03:23 -0600, dana wrote:
> On 25 Feb 2019, at 20:49, Philippe Troin <phil@xxxxxxxx> wrote:
> > Would it make sense to use "command ls" instead of "ls" for remote
> > directory listings in _remote_files?  That would make sure that no
> > aliases nor functions are involved.
> 
> That *seems* reasonable...?
> 
> Now that you mention it, GNU ls changed its default quoting behaviour somewhat
> recently. I think it only quotes when (a) QUOTING_STYLE is set, (b)
> one of the
> quoting options is given on the command line, or (c) the output is a
> TTY — so
> it's unlikely to be an issue for _remote_files, given how it's
> normally used.
> But maybe it'd be a good idea to force it off anyway, just in case?

I'm completely unaware of how QUOTING_STYLE could possibly be getting
us into trouble, but the way you call the binary (variable=value
command ls) is bourne-shell only (bash, sh, ash, ksh), and will not
work if the remote system is using c-shells (csh, tcsh).
I'd recommend using env, as in:

+  remfiles=(${(M)${(f)"$(
+    _call_program files $cmd $cmd_args $host \
+      env QUOTING_STYLE=literal ls -d1FL -- "$rempat" > 2>/dev/null
+  )"}%%[^/]#(|/)})

That will work everywhere.
Now, I haven't seen anyone using c-shells in a very long while, but I'm
sure there are some holdouts :-)

Since you use "env" instead of calling ls directory, you don't need
command anymore, because no alias expansion will occur for ls.
I assume we don't care about global aliases, which none of the proposed
solutions would handle anyways.

Phil.

> diff --git a/Completion/Unix/Type/_remote_files
> b/Completion/Unix/Type/_remote_files
> index 267715a51..89cf102cf 100644
> --- a/Completion/Unix/Type/_remote_files
> +++ b/Completion/Unix/Type/_remote_files
> @@ -59,7 +59,10 @@ if zstyle -T ":completion:${curcontext}:files"
> remote-access; then
>    fi
>  
>    # remote filenames
> -  remfiles=(${(M)${(f)"$(_call_program files $cmd $cmd_args $host ls
> -d1FL -- "$rempat" 2>/dev/null)"}%%[^/]#(|/)})
> +  remfiles=(${(M)${(f)"$(
> +    _call_program files $cmd $cmd_args $host \
> +      QUOTING_STYLE=literal command ls -d1FL -- "$rempat"
> 2>/dev/null
> +  )"}%%[^/]#(|/)})
>  
>    compset -P '*/'
>    compset -S '/*' || (( ${args[(I)-/]} )) || suf='remote file'
> 



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