zsh-workers
 help / color / mirror / code / Atom feed
* ssh host completion: ~/.ssh/config vs /etc/hosts
@ 2015-08-10 10:33 Moritz Bunkus
  2015-08-10 19:50 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Moritz Bunkus @ 2015-08-10 10:33 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 1187 bytes --]

Hey,

zsh 5.0.8

I just noticed this interesting thing: if certain hosts are listed in
/etc/hosts then the ssh completion will complete _but not list_ hosts in
~/.ssh/config that have the same prefix.

For example, let's take the following entries from /etc/hosts:

172.16.1.2 testme-backup
172.16.1.3 testme-vcenter

Let's assume further that I also have the following in my ~/.ssh/config:

Host testme-nagios
  HostName 172.16.1.4

Host other-master
  HostName 172.16.2.1

Host other-backup
  HostName 162.16.2.2

Now typing »ssh testme-<TAB>« will list testme-backup and
testme-vcenter but not testme-nagios. Typing »ssh testme-n<TAB>«,
however, will compelte to »ssh testme-nagios«.

On the other hand typing »ssh other-<TAB>« will list both entries from
~/.ssh/config, other-master and other-backup. There are no entries in
/etc/hosts that start with other-.

Here's how to reproduce it:

1. Create the appropriate entries in /etc/hosts and ~/.ssh/config.

2. Start a shell and initialize the completion system:

zsh -f
autoload -Uz compinit
compinit

3. Try to complete »ssh testme-« and observe the bug.

Kind regards,
mosu

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: ssh host completion: ~/.ssh/config vs /etc/hosts
  2015-08-10 10:33 ssh host completion: ~/.ssh/config vs /etc/hosts Moritz Bunkus
@ 2015-08-10 19:50 ` Bart Schaefer
  2015-08-11 12:45   ` Moritz Bunkus
  2015-08-15  0:34   ` Vincent Lefevre
  0 siblings, 2 replies; 5+ messages in thread
From: Bart Schaefer @ 2015-08-10 19:50 UTC (permalink / raw)
  To: zsh-workers; +Cc: Moritz Bunkus

On Aug 10, 12:33pm, Moritz Bunkus wrote:
}
} I just noticed this interesting thing: if certain hosts are listed in
} /etc/hosts then the ssh completion will complete _but not list_ hosts in
} ~/.ssh/config that have the same prefix.

At the very top of _ssh_hosts is:

  # If users-hosts matches, we shouldn't complete anything else.

The users-hosts completion looks at /etc/hosts and ~/.ssh/known_hosts,
so hosts from your ~/.ssh/config are only completed when no possible
matches are found in either of those other places.

(Or at least I think that's what's going on, because the very next
thing in _ssh_hosts is to examine ~/.ssh/config (or the config file
name following the -F option).)

The explanation is here:

    http://www.zsh.org/mla/users/2007/msg00233.html

It seems a bit odd that this kicks in when there is no user-name part
in the word being completed.


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

* Re: ssh host completion: ~/.ssh/config vs /etc/hosts
  2015-08-10 19:50 ` Bart Schaefer
@ 2015-08-11 12:45   ` Moritz Bunkus
  2015-08-11 16:19     ` Bart Schaefer
  2015-08-15  0:34   ` Vincent Lefevre
  1 sibling, 1 reply; 5+ messages in thread
From: Moritz Bunkus @ 2015-08-11 12:45 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 886 bytes --]

Hey,

thanks for the pointer, Bart. Reverting the patch mentioned in

>     http://www.zsh.org/mla/users/2007/msg00233.html

restores the behavior I want (and which I find less confusing, to be
honest): »ssh testme-<TAB>« now lists both the entries from /etc/hosts
as well as those from ~/.ssh/config.

> It seems a bit odd that this kicks in when there is no user-name part
> in the word being completed.

Even adding user@ I would expect all possible hosts to be listed, not
just the ones from /etc/hosts… To me the current behavior looks like a
bug. Why should entries from /etc/hosts be exclusive in any shape or
form? What makes them more special?

Note that I'm not really arguing against what the user in msg00233.html
wants to do. I'm talking about ssh completion's default behavior. Solely
from the point of view of ease of use.

Kind regards,
mosu

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: ssh host completion: ~/.ssh/config vs /etc/hosts
  2015-08-11 12:45   ` Moritz Bunkus
@ 2015-08-11 16:19     ` Bart Schaefer
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2015-08-11 16:19 UTC (permalink / raw)
  To: zsh-workers

On Aug 11,  2:45pm, Moritz Bunkus wrote:
}
} > It seems a bit odd that this kicks in when there is no user-name part
} > in the word being completed.
} 
} Even adding user@ I would expect all possible hosts to be listed, not
} just the ones from /etc/hosts... To me the current behavior looks like a
} bug. Why should entries from /etc/hosts be exclusive in any shape or
} form? What makes them more special?

It's not (intended to be) /etc/hosts that's special, rather it's meant
to be the values in the user's explicit zstyles.  It just happens that
the "hosts" style has a default completion function _hosts, so that is
run by _combination, and _ssh_hosts has no way to know that the results
came from that default rather than from the literal styles.

This is the "[case] where this gives less than optimum behaviour" that
PWS speculated about in the patch in users/11333.


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

* Re: ssh host completion: ~/.ssh/config vs /etc/hosts
  2015-08-10 19:50 ` Bart Schaefer
  2015-08-11 12:45   ` Moritz Bunkus
@ 2015-08-15  0:34   ` Vincent Lefevre
  1 sibling, 0 replies; 5+ messages in thread
From: Vincent Lefevre @ 2015-08-15  0:34 UTC (permalink / raw)
  To: zsh-workers

On 2015-08-10 12:50:39 -0700, Bart Schaefer wrote:
> On Aug 10, 12:33pm, Moritz Bunkus wrote:
> }
> } I just noticed this interesting thing: if certain hosts are listed in
> } /etc/hosts then the ssh completion will complete _but not list_ hosts in
> } ~/.ssh/config that have the same prefix.
> 
> At the very top of _ssh_hosts is:
> 
>   # If users-hosts matches, we shouldn't complete anything else.
> 
> The users-hosts completion looks at /etc/hosts and ~/.ssh/known_hosts,
> so hosts from your ~/.ssh/config are only completed when no possible
> matches are found in either of those other places.

This behavior doesn't make much sense.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


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

end of thread, other threads:[~2015-08-15  0:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-10 10:33 ssh host completion: ~/.ssh/config vs /etc/hosts Moritz Bunkus
2015-08-10 19:50 ` Bart Schaefer
2015-08-11 12:45   ` Moritz Bunkus
2015-08-11 16:19     ` Bart Schaefer
2015-08-15  0:34   ` Vincent Lefevre

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).