Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


For zsh | 6 comments | Create New Account
Click here to return to the 'For zsh' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
For zsh
Authored by: sabi on Jan 15, '10 08:57:00AM
I've had this set up for years...

# completion of .ssh/hosts
_hosts() {
    local expl hosts

    if ! zstyle -a ":completion:${curcontext}:hosts" hosts hosts
    then
	(( $+_cache_hosts )) ||
	: ${(A)_cache_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}} 
	(( $+_cache_sshconf_hosts )) ||
	: ${(A)_cache_sshconf_hosts:=${${${(M)${(s:# :)${(zj:# :)${(Lf)"$([[ -f ~/.ssh/config ]] && <~/.ssh/config)"}%%\#*}}##host *}#host }/\*}}
	hosts=( "$_cache_hosts[@]" "$_cache_sshconf_hosts[@]")
	_wanted hosts expl host \
	    compadd -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' "$@" -a hosts
    fi
}


[ Reply to This | # ]