From 5ded0ad96740b62ea0214387ee260b515726a05e Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sun, 28 May 2017 11:27:55 -0700 Subject: 41159: handle "Include" and "HostName" lines in ~/.ssh/config Added 2>/dev/null to conceal file access errors. --- ChangeLog | 5 +++++ Completion/Unix/Command/_ssh | 28 +++++++++++++++++----------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8ce4aecf3..68e36e718 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2017-05-28 Barton E. Schaefer + + * 41159 (tweaked): Completion/Unix/Command/_ssh: handle "Include" + and "HostName" lines in ~/.ssh/config + 2017-05-24 Peter Stephenson * Sebastian: 41146: Src/Modules/db_gdbm.c: be more careful about diff --git a/Completion/Unix/Command/_ssh b/Completion/Unix/Command/_ssh index 6763e24e7..28d2c38e7 100644 --- a/Completion/Unix/Command/_ssh +++ b/Completion/Unix/Command/_ssh @@ -680,17 +680,23 @@ _ssh_hosts () { config="$HOME/.ssh/config" fi if [[ -r $config ]]; then - 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 - (*[*?]*) ;; - (*) config_hosts+=("$host") ;; - esac - done - fi - done < "$config" + local key line host + local -a lines=("${(@f)$(<"$config")}") 2>/dev/null + while (($#lines)); do + IFS=$'=\t ' read -r key line <<<"${lines[1]}" + case "$key" in + ((#i)include) + lines[1]=("${(@f)$(cd $HOME/.ssh; cat ${(z)~line})}") 2>/dev/null;; + ((#i)host(|name)) + for host in ${(z)line}; do + case $host in + (*[*?]*) ;; + (*) config_hosts+=("$host") ;; + esac + done ;& + (*) shift lines;; + esac + done if (( ${#config_hosts} )); then _wanted hosts expl 'remote host name' \ compadd -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' "$@" $config_hosts -- cgit 1.4.1