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

Re: autocompletion with remote hosts



On 2009-12-21 at 18:36 +0100, Mr.SpOOn wrote:
> in bash I somehow managed to have autocompletion for remote hosts and
> directory when I used ssh and scp.
> 
> I can't find a way to have the same in zsh.
> Can you help me?

It works out-of-the-box, once you activate the new completion system.
Hostnames can be specified by style, but if not overriden then:
  * first hosts from the known_hosts files (system and user) are used
  * if those are not matched by what's typed so far, hosts from "Host "
    rules in the user ~/.ssh/config file are used
and you *really* want to either have ssh-agent running, with pubkey
authentication, or be using Kerberised SSH, to use this functionality.

Oh, and if you have "getent" installed, { getent hosts } is used; so in
an LDAP environment, this can cause tab-completion to get *really* slow
unless you override the hosts completion with zstyle.

The zsh completion calls ssh with { -o BatchMode=yes }, so you need to
be able to authenticate automatically.  And of course you should have a
"clean" shell setup, so that nothing is emitted to stdout or stderr when
you ssh to a host to run a command non-interactively.

% ssh other-host true

If you see output from that command, fix your shell setup.

....% zsh -f
mybox% bindkey -e
mybox% autoload compinit
mybox% compinit
mybox% ssh <tab>
[ see users and hosts ]
mybox% ssh -l nobody <tab>
[ see hosts from ~/.ssh/known_hosts ]
mybox% ssh -l nobody co<tab>
[ get a completion I have in ~/.ssh/config which doesn't match a
  known_hosts entry ]

You can control the completion with zstyle to set various tags; these
are documented in zshcompsys(1).  'users' and 'hosts' are the easiest.

Regards,
-Phil



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