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

Re: An improved "hosts" completion handling



Thanks for that.  I was using a similar trick and was now seeing that
problem and hadn't had time to track it down (too many other fires to put
out).

Christopher Browne wrote:
> I had been using some code I'd seen "out there" to pull known_hosts as
> a way of setting up a $hosts value so that ssh/telnet could do tab
> completion on host names.
>
> I think this was the source, more or less...
> http://www.2701.org/archive/200405030000.html
>
> With the changes in openssh, of late, ~/.ssh/known_hosts is now
> littered with encoded host names that were getting pulled in such that
> I'd get tab completion looking like the following:
>
> cbbrowne@dba2:~/Slony-I/slony1-HEAD-pristine> ssh rg  ssh
> rg570-da-logdbs
>   Wednesday 17:20:40
> rg570-da-logdbs
> rg570-da-logdbs1
> rg570-da-logdbs1.nj.site\ ssh-rsa\
> AAAAB3NzaC1yc2EAAAABIwAAAIEAn7BPZtUqqjJzpVszaI71KUCVyvGicrOvUTFO4EiGzCHm7lYtJIbN0MblFo4CGwq3Z7cgzMwn/qdSxIXFnlIHIpPHojcZAnbSFXrJMIKB45VjK6XgFOB7ZQtpKg252F/nXV7vaTa/xgI6H+tza4w5UI5AZnrD/knq+l3qtSyuBDU=
> rg570-da-logdbs2
> rg570-da-logdbs2.nj.site\ ssh-rsa\
> AAAAB3NzaC1yc2EAAAABIwAAAIEAn7BPZtUqqjJzpVszaI71KUCVyvGicrOvUTFO4EiGzCHm7lYtJIbN0MblFo4CGwq3Z7cgzMwn/qdSxIXFnlIHIpPHojcZAnbSFXrJMIKB45VjK6XgFOB7ZQtpKg252F/nXV7vaTa/xgI6H+tza4w5UI5AZnrD/knq+l3qtSyuBDU=
>
> Bleah.  That's awful.
>
> The following showed an alternative that does some better parsing, as
> well as reading IP addresses.
>
> http://www.zsh.org/mla/workers/2006/msg00280.html
>
> Here's my adaption of this:
>
> for file in $HOME/.ssh/known_hosts /etc/ssh/known_hosts; do
>   if [[ -r ${file} ]] ; then
>     _cache_hosts+=(${${${(u)${(f)"$(<${file})"}%%[
> ,|#]*}:#(#s)[0-9]##.[0-9]##.[0-9]##.[0-9]##(#e)}:#(#s)[0-9a-f:]##(#e)})
>   fi
> done
> zstyle ':completion:*:hosts' hosts $_cache_hosts
>
> Hope that is of assistance to others...
> --
> http://linuxfinances.info/info/linuxdistributions.html
> "...  memory leaks  are  quite acceptable  in  many applications  ..."
> (Bjarne Stroustrup, The Design and Evolution of C++, page 220)
>



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