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

[PATCH] _ssh: parse Host=hostname format in $HOME/.ssh/config



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



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