zsh-workers
 help / color / mirror / code / Atom feed
* PATCH _hosts: can complete hosts listed on ~/.ssh/config
@ 2003-03-11  5:38 Tatsuki Sugiura
  2003-03-11  7:26 ` Borzenkov Andrey
  2003-03-11 13:53 ` Oliver Kiddle
  0 siblings, 2 replies; 3+ messages in thread
From: Tatsuki Sugiura @ 2003-03-11  5:38 UTC (permalink / raw)
  To: zsh-workers

Hello.

Usually, "/etc/hosts" dos not contain hostname to wish to complete.
This pactch parse ~/.ssh/config and pick up hosts listed as "Host"
or "HostName".

What about this?

==============
--- _hosts.orig 2003-03-11 14:21:35.000000000 +0900
+++ _hosts      2003-03-11 14:22:54.000000000 +0900
@@ -1,12 +1,15 @@
-#compdef ftp ping rwho rup xping traceroute host aaaa zone mx ns soa txt
+#compdef ftp ping rwho rup xping traceroute host aaaa zone mx ns soa txt mtr dnsip hping2 hping nmap tcptraceroute
 
 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(|name) *}#host(|name) }/\*}}
 
-  hosts=( "$_cache_hosts[@]" )
+  hosts=( "$_cache_hosts[@]" "$_cache_sshconf_hosts[@]")
 fi
 
 _wanted hosts expl host \
==============

-- 
Tatsuki Sugiura   mailto:sugi@nemui.org


^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: PATCH _hosts: can complete hosts listed on ~/.ssh/config
  2003-03-11  5:38 PATCH _hosts: can complete hosts listed on ~/.ssh/config Tatsuki Sugiura
@ 2003-03-11  7:26 ` Borzenkov Andrey
  2003-03-11 13:53 ` Oliver Kiddle
  1 sibling, 0 replies; 3+ messages in thread
From: Borzenkov Andrey @ 2003-03-11  7:26 UTC (permalink / raw)
  To: 'Tatsuki Sugiura', zsh-workers


> Hello.
> 
> Usually, "/etc/hosts" dos not contain hostname to wish to complete.
> This pactch parse ~/.ssh/config and pick up hosts listed as "Host"
> or "HostName".
> 
> What about this?
> 

I agree with idea but I do not like use of cache without revalidation. Your
code won't pick changes done after ~/.ssh/config has been first time read.

It is not the only place where (useful) revalidation is missing but let's
not introduce new one.

Probably we need general purpose utility for cache variables without backing
store. Like saving mtime in __cache_sshconf_hosts_mtime and rechecking it
next time.

Alternatively do not bother with caching at all. File is expected to be
small enough so parsing it does not add significant overhead.

-andrey

> ==============
> --- _hosts.orig 2003-03-11 14:21:35.000000000 +0900
> +++ _hosts      2003-03-11 14:22:54.000000000 +0900
> @@ -1,12 +1,15 @@
> -#compdef ftp ping rwho rup xping traceroute host aaaa zone mx ns soa txt
> +#compdef ftp ping rwho rup xping traceroute host aaaa zone mx ns soa txt
> mtr dnsip hping2 hping nmap tcptraceroute
> 
>  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(|name)
> *}#host(|name) }/\*}}
> 
> -  hosts=( "$_cache_hosts[@]" )
> +  hosts=( "$_cache_hosts[@]" "$_cache_sshconf_hosts[@]")
>  fi
> 
>  _wanted hosts expl host \
> ==============
> 
> --
> Tatsuki Sugiura   mailto:sugi@nemui.org


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PATCH _hosts: can complete hosts listed on ~/.ssh/config
  2003-03-11  5:38 PATCH _hosts: can complete hosts listed on ~/.ssh/config Tatsuki Sugiura
  2003-03-11  7:26 ` Borzenkov Andrey
@ 2003-03-11 13:53 ` Oliver Kiddle
  1 sibling, 0 replies; 3+ messages in thread
From: Oliver Kiddle @ 2003-03-11 13:53 UTC (permalink / raw)
  To: Tatsuki Sugiura; +Cc: zsh-workers

Tatsuki Sugiura wrote:
> Hello.
> 
> Usually, "/etc/hosts" dos not contain hostname to wish to complete.
> This pactch parse ~/.ssh/config and pick up hosts listed as "Host"
> or "HostName".

Picking up hosts from a "Host" line is perhaps not wise because it can
contain ssh specific nicknames and wildcards. I'd be more inclined to
use ~/.ssh/known_hosts.

You can use a style to specify your hosts for ssh:
zstyle ':completion:*:(ssh|scp):*:my-accounts' users-hosts user@host

Or use this:
  ${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[0-9]*}%%\ *}%%,*}
to set the hosts style.

That said, I appreciate that it could be more intelligent out-of-the-box.
The way I envision that eventually working involves integrating with user
and port completion more flexibly than _combination and it isn't trivial.

Oliver


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-03-11 13:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-11  5:38 PATCH _hosts: can complete hosts listed on ~/.ssh/config Tatsuki Sugiura
2003-03-11  7:26 ` Borzenkov Andrey
2003-03-11 13:53 ` Oliver Kiddle

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).