zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] _ssh: parse Host=hostname format in $HOME/.ssh/config
@ 2015-08-03  1:31 Eric Cook
  0 siblings, 0 replies; only message in thread
From: Eric Cook @ 2015-08-03  1:31 UTC (permalink / raw)
  To: zsh-workers

Currently _ssh_hosts() assumes the format of .ssh/config
is ''Directive Value'', not ''Directive=Value'' or
''Directive = Value''. This patch allows matching those possible
formats.

I also scoped the IFS change to read since that, from
what i can tell, is it's intended usecase. and prevents
_wanted from showing the parsed hostnames as one element.

Unfornately this code path is only taken when
_combination fails. Which seems intentional, users/11333.
''
ssh nonmatchingprefix<tab>
''

But helps make code like this, become less necessary.
''
    # host completion
    if is42 ; then
        [[ -r ~/.ssh/config ]] && _ssh_config_hosts=(${${(s: :)${(ps:\t:)${${(@M)${(f)"$(<$HOME/.ssh/config)"}:#Host *}#Host}}}:#*[*?]*}) || _ssh_config_hosts=()
        [[ -r ~/.ssh/known_hosts ]] && _ssh_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_hosts=()
        [[ -r /etc/hosts ]] && : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}} || _etc_hosts=()
    else
        _ssh_config_hosts=()
        _ssh_hosts=()
        _etc_hosts=()
    fi
    hosts=(
        $(hostname)
        "$_ssh_config_hosts[@]"
        "$_ssh_hosts[@]"
        "$_etc_hosts[@]"
        localhost
    )
    zstyle ':completion:*:hosts' hosts $hosts
''
---
 Completion/Unix/Command/_ssh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Completion/Unix/Command/_ssh b/Completion/Unix/Command/_ssh
index 2be5672..15daf0f 100644
--- a/Completion/Unix/Command/_ssh
+++ b/Completion/Unix/Command/_ssh
@@ -573,8 +573,8 @@ _ssh_hosts () {
     config="$HOME/.ssh/config"
   fi
   if [[ -r $config ]]; then
-    local IFS=$'\t ' key hosts host
-    while read key hosts; do
+    local key hosts host
+    while IFS=$'=\t ' read -r key hosts; do
       if [[ "$key" == (#i)host ]]; then
          for host in ${(z)hosts}; do
             case $host in
-- 
2.5.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-08-03  1:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-03  1:31 [PATCH] _ssh: parse Host=hostname format in $HOME/.ssh/config Eric Cook

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