zsh-workers
 help / color / mirror / code / Atom feed
* autocompletion with ssh and .ssh/config
@ 2010-07-17 22:59 David Duponchel
  2010-07-18  5:21 ` Benjamin R. Haskell
  0 siblings, 1 reply; 4+ messages in thread
From: David Duponchel @ 2010-07-17 22:59 UTC (permalink / raw)
  To: zsh-workers

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

Hi,

I have some hosts defined in my .ssh/config file. Example :
Host bar
    HostName 1.2.3.4

Host baz
    HostName 2.3.4.5

When I type ssh <tab>, only my users and hosts in /etc/hosts are displayed
(my .ssh/config is ignored).
With ssh ba<tab> the autocompletion is correctly done and propose bar and
baz.
Same behavior with ssh user@<tab> and ssh user@ba<tab>

Expected : Hosts from ssh/config are proposed by the autocompletion with the
other hosts.

I did some research and the root of the problem seems to be in
Completion/Unix/Command/_ssh, function _ssh_hosts : the function exists too
early (before reading ssh/config).


Used .zshrc :
autoload -U compinit
compinit

Tested env : zsh 4.3.10 and 4.3.10-dev-1, OS : Archlinux.


Thanks
David Duponchel

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

* Re: autocompletion with ssh and .ssh/config
  2010-07-17 22:59 autocompletion with ssh and .ssh/config David Duponchel
@ 2010-07-18  5:21 ` Benjamin R. Haskell
  2010-07-18  8:51   ` Mikael Magnusson
  0 siblings, 1 reply; 4+ messages in thread
From: Benjamin R. Haskell @ 2010-07-18  5:21 UTC (permalink / raw)
  To: David Duponchel; +Cc: zsh-workers

On Sun, 18 Jul 2010, David Duponchel wrote:

> Hi,
> 
> I have some hosts defined in my .ssh/config file. Example :
> Host bar
>     HostName 1.2.3.4
> 
> Host baz
>     HostName 2.3.4.5
> 
> When I type ssh <tab>, only my users and hosts in /etc/hosts are 
> displayed (my .ssh/config is ignored).
> With ssh ba<tab> the autocompletion is correctly done and propose bar 
> and baz.
> Same behavior with ssh user@<tab> and ssh user@ba<tab>
> 
> Expected : Hosts from ssh/config are proposed by the autocompletion 
> with the other hosts.
> 
> I did some research and the root of the problem seems to be in 
> Completion/Unix/Command/_ssh, function _ssh_hosts : the function 
> exists too early (before reading ssh/config).
> 
> 
> Used .zshrc :
> autoload -U compinit
> compinit
> 
> Tested env : zsh 4.3.10 and 4.3.10-dev-1, OS : Archlinux.
> 

Confirmed with a pretty recent git build.

Host from ~/.ssh/config aren't proposed until hosts found from other 
methods are exhausted.  The biggest reason that seems wrong (IMO) is 
that 'other methods' includes ~/.ssh/known_hosts.  So, a host I've never 
ssh'ed to won't be offered until I've ssh'ed to it.

With 'acerwin.internal' and 'acerlin.internal' as hosts that show up 
already, I tested by adding, to an already large ~/.ssh/config:

Host acerjjjconfig

And editing ~/.ssh/known_hosts to add acerjjjkh as an alias of some 
other host.

Then acerlin, acerwin, and acerjjjkh are offered in the initial list, 
but acerjjjconfig isn't offered until I type the 'c' (which is also 
annoying because acerj<Tab> completes at that point unambiguously to 
acerjjjkh).

The two _combinations branches in _ssh_hosts that use the user-hosts tag 
seem to be returning intentionally if anything matches.  Removing the ' 
&& return' from each seems to make things better.  But, I'm not sure of 
the use-case that those are supporting.

Another thing to note is that I couldn't get it to recognize HostName 
when HostName was indented as David had it.  E.g. adding:

Host acerjjjconfig
	HostName acerjjjindented

only added acerjjjconfig to the list of completions.

-- 
Best,
Ben


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

* Re: autocompletion with ssh and .ssh/config
  2010-07-18  5:21 ` Benjamin R. Haskell
@ 2010-07-18  8:51   ` Mikael Magnusson
  2010-07-18 18:21     ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Mikael Magnusson @ 2010-07-18  8:51 UTC (permalink / raw)
  To: Benjamin R. Haskell; +Cc: David Duponchel, zsh-workers

On 18 July 2010 07:21, Benjamin R. Haskell <zsh@benizi.com> wrote:
> On Sun, 18 Jul 2010, David Duponchel wrote:
>
>> Hi,
>>
>> I have some hosts defined in my .ssh/config file. Example :
>> Host bar
>>     HostName 1.2.3.4
>>
>> Host baz
>>     HostName 2.3.4.5
>>
>> When I type ssh <tab>, only my users and hosts in /etc/hosts are
>> displayed (my .ssh/config is ignored).
>> With ssh ba<tab> the autocompletion is correctly done and propose bar
>> and baz.
>> Same behavior with ssh user@<tab> and ssh user@ba<tab>
>>
>> Expected : Hosts from ssh/config are proposed by the autocompletion
>> with the other hosts.
>>
>> I did some research and the root of the problem seems to be in
>> Completion/Unix/Command/_ssh, function _ssh_hosts : the function
>> exists too early (before reading ssh/config).
>>
>>
>> Used .zshrc :
>> autoload -U compinit
>> compinit
>>
>> Tested env : zsh 4.3.10 and 4.3.10-dev-1, OS : Archlinux.
>>
>
> Confirmed with a pretty recent git build.
>
> Host from ~/.ssh/config aren't proposed until hosts found from other
> methods are exhausted.  The biggest reason that seems wrong (IMO) is
> that 'other methods' includes ~/.ssh/known_hosts.  So, a host I've never
> ssh'ed to won't be offered until I've ssh'ed to it.
>
> With 'acerwin.internal' and 'acerlin.internal' as hosts that show up
> already, I tested by adding, to an already large ~/.ssh/config:
>
> Host acerjjjconfig
>
> And editing ~/.ssh/known_hosts to add acerjjjkh as an alias of some
> other host.
>
> Then acerlin, acerwin, and acerjjjkh are offered in the initial list,
> but acerjjjconfig isn't offered until I type the 'c' (which is also
> annoying because acerj<Tab> completes at that point unambiguously to
> acerjjjkh).
>
> The two _combinations branches in _ssh_hosts that use the user-hosts tag
> seem to be returning intentionally if anything matches.  Removing the '
> && return' from each seems to make things better.  But, I'm not sure of
> the use-case that those are supporting.
>
> Another thing to note is that I couldn't get it to recognize HostName
> when HostName was indented as David had it.  E.g. adding:
>
> Host acerjjjconfig
>        HostName acerjjjindented
>
> only added acerjjjconfig to the list of completions.

Here's the commit that introduced the &&returns,
http://zsh.git.sourceforge.net/git/gitweb.cgi?p=zsh/zsh;a=commitdiff;h=7072c10ae223e24f601b3

-- 
Mikael Magnusson


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

* Re: autocompletion with ssh and .ssh/config
  2010-07-18  8:51   ` Mikael Magnusson
@ 2010-07-18 18:21     ` Peter Stephenson
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Stephenson @ 2010-07-18 18:21 UTC (permalink / raw)
  To: zsh-workers

On Sun, 18 Jul 2010 10:51:32 +0200
Mikael Magnusson <mikachu@gmail.com> wrote:
> On 18 July 2010 07:21, Benjamin R. Haskell <zsh@benizi.com> wrote:
> > On Sun, 18 Jul 2010, David Duponchel wrote:
> >> I have some hosts defined in my .ssh/config file. Example :
> >> Host bar
> >>     HostName 1.2.3.4
> >>
> >> Host baz
> >>     HostName 2.3.4.5
> >>
> >> When I type ssh <tab>, only my users and hosts in /etc/hosts are
> >> displayed (my .ssh/config is ignored).
> >> With ssh ba<tab> the autocompletion is correctly done and propose bar
> >> and baz.
> >
> > Host from ~/.ssh/config aren't proposed until hosts found from other
> > methods are exhausted.  The biggest reason that seems wrong (IMO) is
> > that 'other methods' includes ~/.ssh/known_hosts.  So, a host I've never
> > ssh'ed to won't be offered until I've ssh'ed to it.
> 
> Here's the commit that introduced the &&returns,
> http://zsh.git.sourceforge.net/git/gitweb.cgi?p=zsh/zsh;a=commitdiff;h=7072c10ae223e24f601b3

... which contains little useful information but at least refers to where
the information is.  The correct reference is zsh-users/11333:

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

This fixed a problem that user@... completed machines that weren't
associated with that username even though the association is explicit.

The problem seems to be that user completion is being assumed even if it
hasn't happened, i.e. user@host completion is treated as succesful even
if there's no user@ bit.

The fix would be to separate these cases, i.e. ensure the return only
happens if a user was actually matched.  Simply removing the returns
would reintroduce the user-host completion bug.  I haven't probed any
deeper, but presumably _combination isn't up to the job on its own, and
it'll need an extra test somewhere.  Examination suggests the problem's
probably in the second branch, where there's no existing "@".  However,
I can't see offhand what the command is trying to do.

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


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

end of thread, other threads:[~2010-07-18 18:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-17 22:59 autocompletion with ssh and .ssh/config David Duponchel
2010-07-18  5:21 ` Benjamin R. Haskell
2010-07-18  8:51   ` Mikael Magnusson
2010-07-18 18:21     ` Peter Stephenson

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