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

Ssh completion from ~/.ssh/config



I would like to have ssh complete with hosts from my ~/.ssh/config, but I
can't get it to work. I don't know if I'm missing something obvious.

Suppose I have the following in my ssh-config:

Host myhost
  HostName 192.168.1.1
  User jesper

Typing "ssh <tab>" I would like it to supply "myhost".

Looking through the standard completion script _ssh, I see the following
lines:

  # If users-hosts matches, we shouldn't complete anything else.
  if [[ "$IPREFIX" == *@ ]]; then
      _combination -s '[:@]' my-accounts users-hosts "users=${IPREFIX/@}"
hosts "$@" && return
   else
       _combination -s '[:@]' my-accounts users-hosts \
       ${opt_args[-l]:+"users=${opt_args[-l]:q}"} hosts "$@" && return
  fi

In this case the else statement is executed. Since I have not defined any
"my-accounts", the completion file _hosts is auto-loaded. This script reads
several files to find possible completions (among others /etc/hosts and
~/.ssh/known_hosts).

Since this fulfills _combination, the lines in _ssh which parse
~/.ssh/config are never executed.

If I comment out the lines I quoted above it works as I would like it to
work, but with the obvious drawback that I have modified a file that is
part of the zsh distribution, and I need to keep track of this file every
time I upgrade.

I could also specify "my-accounts" or "hosts" in my .zshrc, but then I need
to keep it in sync with my ~/.ssh/config.

Is there no way to get this to work the way I like through some
configuration that I have missed?

Jesper


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