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

Re: autocompletion with ssh and .ssh/config



On 18 July 2010 07:21, Benjamin R. Haskell <zsh@xxxxxxxxxx> 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



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