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

Re: Completion

On Feb 22,  3:24pm, Andy Spiegl wrote:
} Subject: Re: Completion
} Say I press TAB after this:
}  $ scp foo me@bar:/usr/local/_
} Then I would like to see the files and directories on the remote host "bar",
} but what I see is the possible completions for my own host.

(A day without a patch is like a day without sunshine.  Hmm, we're having
one of those here right now ...)

The change to _ssh is pretty trival.  A more complex _remote_files is left
as an excercise for those with more free time to kill.


(1) It doesn't know from ssh/ssh1/ssh2/scp/scp1/scp2/etc.  But then neither
do the rest of the ssh completions.

(2) Menu completion, at least with auto-menu, appears to execute the remote
command a second time to generate the menu.  (Does this indicate a bug in
the C code?)  That makes it pretty slow for the first two TABs.

(3) There's a remote (pun?) possibility that expansion could interfere when
using expand-or-complete; this might work best with complete-word and the
_expand completer.

(4) Because names are listed with "echo" on the remote host, wildcards are
expanded when generating the completion, even if your styles say not to;
i.e. you get part of the effect of _expand, always.  This could be fixed
by using ${(q)words[CURRENT]#*:}\* in _remote_files, but then expansion
won't work at all.  I think it's OK this way, except possibly that:

(5) Parameter references are expanded on the remote machine when creating
the completions, but on the local machine when the command is executed.

(6) "No match" is handled badly if e.g. the remote login shell is csh.

Index: Completion/User/_ssh
@@ -1,5 +1,11 @@
 #compdef ssh slogin scp ssh-add ssh-agent ssh-keygen
+_remote_files () {
+  # This is extremely simple-minded; could parse "ls -F" output to do
+  # colorings and LIST_TYPES and so on, but I'm just not that ambitious.
+  compadd $(ssh ${words[CURRENT]%:*} echo ${words[CURRENT]#*:}\*)
 _ssh () {
   local curcontext="$curcontext" state lstate line ret=1 expl args tmp
   typeset -A opt_args
@@ -172,7 +178,7 @@
     elif [[ -n "$state" ]]; then
       if compset -P '*:'; then
-        _files && ret=0
+        _remote_files && ret=0
       elif compset -P '*@'; then
         _wanted hosts expl host && _ssh_hosts -S: "$expl[@]" && ret=0

Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

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