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

Re: hostname completion for ssh / scp

> On 2016-11-05 05:42, Bart Schaefer wrote:
> On Nov 3,  8:11pm, Fourhundred Thecat wrote:
> } Subject: hostname completion for ssh / scp
> }
> }   ssh <TAB>
> } 
> } it offers me only the hostnames listed in ~/.ssh/config and completely
> } ignores global ones defined in /etc/hosts
> } 
> } Tested on zsh 4.3.17
> What does
>     getent hosts
> return on your system?  That's where _hosts gets the list of hosts.

getent hosts only returns first two lines from /etc/hosts, and ignores
the rest:       localhost       laptop

I believe, getent hosts only returns hosts which have ip address
specified in /etc/hosts, such as:	myserver1.com

> If getent isn't returning anything useful, you can replace it:
> zstyle ':completion:*:hosts' command 'cat /etc/hosts'

I would like to keep the completion from ~/.ssh/config and add
completion from /etc/hosts.

I cannot just use

  zstyle ':completion:*:hosts' command 'cat /etc/hosts ~/.ssh/config'

because the syntax in ~/.ssh/config is more tricky (multiline host
definition), and I don't want options to be interpreted as hostnames.

> Or explicitly list all the hosts yourself:
> zstyle ':completion:*:hosts' hosts $(awk '/^[^#]/ {print $2}' /etc/hosts)

same as above

> Note there have been several other fixes/improvements to ssh host-gathering
> since zsh 5.0.

can I simply copy Unix/_ssh from zsh 5.0. and use it on zsh 4.3.17 ?

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