Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: patch for ssh completion
- X-seq: zsh-workers 40700
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Jeremy Cantrell <jmcantrell@xxxxxxxxx>
- Subject: Re: patch for ssh completion
- Date: Thu, 2 Mar 2017 12:12:29 +0000
- Cc: zsh-workers@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= mesmtp; bh=FAIpDe+qfEIj+grNJsbNqqQQuRo=; b=rgep6xrkGPpmQL1q6zmvp ey8kgjL/cN6Kh8y9tXCYcKXgnUBuuyVXm8pOORrF9tPVukarhumBDfQIH4EzR6qa g/TgQcfejwJNGf+uIvMDdmFVBf59KH4HcT4SzsqdSFDAAJSktLAr3M3ibKsxyMir IAHgKR2UasEgT6HWVygDUs=
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= smtpout; bh=FAIpDe+qfEIj+grNJsbNqqQQuRo=; b=Chj0rRPjnpY3M1xj+5xn GD2lUrM+qxPQ8nDnp+/3XR/Cms9Vf9V7meO48NCcyHnOCYtBbQoNCyLmj7g5UJf2 rBF/T9DwOhZd7x4yvee0L2vzCPSGXADnoTFef2V21eAbOf0J0qO/ZWzbkP8/JSmP 4CN2n/39tah1mzY/znI2OLk=
- In-reply-to: <CAHM1PU2toZMyHPPaQTkbTvctEy9qm9aLOvtMm1CVOpxWW_Wodg@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAHM1PU2toZMyHPPaQTkbTvctEy9qm9aLOvtMm1CVOpxWW_Wodg@mail.gmail.com>
Jeremy Cantrell wrote on Tue, Feb 28, 2017 at 11:17:29 -0800:
> Hello!
>
> I've found a tiny problem with the ssh completion script where any host
> entries defined in included configuration files do not appear as choices
> when completing. I've attached a patch that fixes it for me. Below is an
> example that illustrates the problem:
>
> ~/.ssh/config:
> Include hosts
>
> ~/.ssh/hosts:
> Host example
> HostName example.local
From ssh_config(5):
Include
Include the specified configuration file(s). Multiple pathnames
may be specified and each pathname may contain glob(3) wildcards
and, for user configurations, shell-like ‘~’ references to user
home directories. Files without absolute paths are assumed to be
in ~/.ssh if included in a user configuration file or /etc/ssh if
included from the system configuration file. Include directive
may appear inside a Match or Host block to perform conditional
inclusion.
> Thanks,
> Jeremy
> --- /usr/share/zsh/functions/Completion/Unix/_ssh 2016-12-22 11:27:00.000000000 -0800
> +++ packages/base/.local/share/zsh/functions/_ssh 2017-02-26 22:37:47.513422235 -0800
> @@ -681,16 +681,21 @@
> fi
> if [[ -r $config ]]; then
> local key hosts host
> + local filename configs=($config)
> + grep '^Include\b' "$config" | sed 's/\s\+/ /g' | cut -d' ' -f2 |
> + while read -r filename; do
> + config=$HOME/.ssh/$filename
This handles your example, but not the other possibilities documented in
the man page, e.g., absolute paths. I expect using those would cause
errors on stderr. (I can't test this since my ssh isn't new enough.)
The «\b» in grep is not in POSIX. It could be changed to match
whitespace explicitly. I assume we'll also want to use builtin
functionality such as ${(M)…:#Include*} instead of external executables.
Can filenames be quoted? I.e., does «Include "foo"» include ~/.ssh/foo
or ~/.ssh/\"foo\"?
Can Include directives be nested? If they can, it'd be nice to handle
that. (But I don't think that's a blocker to accepting the patch)
> while IFS=$'=\t ' read -r key hosts; do
> if [[ "$key" == (#i)host ]]; then
> for host in ${(z)hosts}; do
> case $host in
> (*[*?]*) ;;
> (*) config_hosts+=("$host") ;;
> esac
> done
> fi
> done < "$config"
> + done
Thanks for the patch.
Cheers,
Daniel
Messages sorted by:
Reverse Date,
Date,
Thread,
Author