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

Re: Bug#430146: zsh: please add .ssh/config Hosts to the hosts zstyle completion



On 2007-06-24 at 07:57 -0400, Clint Adams wrote:
> On Sat, Jun 23, 2007 at 12:33:21PM +0100, Pierre Habouzit wrote:
> >   Anyways, I'm not using it anymore because I fancy the
> > .ssh/known_hosts more, but I miss it :)
> 
> We could do something like this to generate matches from ~/.ssh/config .
> Anyone have better ideas?

The Hosts lines in .ssh/config are glob patterns.  Both '*' and '?' are
valid characters.  With farms of machines under a consistent naming
scheme, this comes into play.

Further, multiple patterns can be on the same line, so you can have
hostnames and patterns.  I look at my config now ... ugh.  Way to make
things bad: have a section of your ~/.ssh/config delimited by magic
comments used by another script when generating an updated config file.

> +    if zstyle -t ":completion:${curcontext}:hosts" use-ssh-config; then
> +      [[ -r ~/.ssh/config ]] && _cache_hosts+=(${=${${(M)${(f)"$(<~/.ssh/config)"}:#Host*}#Host }:#*\**})
> +    fi

I think that:
 ${=${${(M)${(f)"$(<~/.ssh/config)"}:#Host*}#Host }:#*\**}
should be:
 ${${=${(M)${(f)"$(<~/.ssh/config)"}:#Host*}#Host }:#*[\*\?]*}

This splits on $IFS earlier so that the outer :# filter applies on a
per-item basis instead of per-line, and adds '?' to the filter pattern.

And people wonder why I laugh when they describe _Perl_ as a line-noise
language.  ;-)

Regards,
-Phil



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