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

Re: scp completion options



On Wed, 27 Jun 2018 00:06:54 +0100
David Woodfall <dave@xxxxxxxxxxxxxx> wrote:
> When I tab complete a scp command such as:
> 
> scp somefile host:somefolder<tab>
> 
> I will always get the current local directory as the first completion
> option if it is any way similar to the name of the remote. Is there a
> way to stop that behaviour and list remote directories first if I'm
> scp'ing /to/ a host? In fact I will always have the local directory
> listed whatever I do.

Hmm... you *should* be able to do something like what's below (which is
rather simplistic, as a demo).  The idea is: if you're on the third word
or after, and the second word didn't have a ":" (so is assumed to be a
local file), then only complete remotely.

But actually I don't see how to get this to work in the case you're
talking about (hence the question marks), because the tag for remote
files is just 'files' so will allow it to complete local files.  This
looks to me like a mistake, and _remote_files should arrange for a
different tag.

I may be missing something, but if I'm not, changing _remote_files ought
to be easy.  There may also be other ways of limiting completion, but
the point remains.


scp_comp_helper() {
  if [[ CURRENT -gt 2 && $words[2] != *:* && ]]; then
    # Complete remotely only...?
    reply=('hosts ????')
  else
    reply=('hosts files')
  fi
}
zstyle -e ':completion:*:complete:scp:*:' tag-order scp_comp_helper


pws



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