zsh and host completion

Hi there

is there a way i can add to my .zshrc so that when i type rsh <tab> it takes the name for a list of hosts

i know it looks in .ssh/know_hosts but i want it for rsh and for a list that i supply

thanks
A

Try this:

zstyle -e ':completion:*:(ssh|scp|sftp|rsh):hosts' hosts 'reply=(${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) /dev/null)"}%%[# ]*}//,/ })'

I found it here.

hi

i acutally got it work using this

knownhosts=( ${${${${(f)"$(<$HOME/.zshhosts)"}:#[0-9]*}%%\ *}%%,*} )
zstyle ':completion:*:(ssh|scp|sftp|rsh):*' hosts $knownhosts

thanks for the help

If you want a separate completion for rsh from a separate list:

zstyle ':completion:*:rsh:*' hosts "${(f)$(<file_with_hosts)}" 
zsh-4.3.11[sysadmin]% cat file_with_hosts 
host1
host2
host3
zsh-4.3.11[sysadmin]% rsh host
- remote host name -
host1  host2  host3

Hi.

Using grep on the /etc/hosts file would provide advantages:

1) Not restricted to zsh,

2) Need not recall the beginning of the host string, only a unique segment,

3) Same technique could be used for any utility that looks up hosts,

Some scripting to diagnose no matches or too many matches could be useful.

Disadvantages -- for a simple script you may need to execute more than once if you make a mistake.

Best wishes ... cheers, drl