Skip to content

Commit

Permalink
41159: handle "Include" and "HostName" lines in ~/.ssh/config
Browse files Browse the repository at this point in the history
Added 2>/dev/null to conceal file access errors.
  • Loading branch information
bartschaefer committed May 28, 2017
1 parent 62c4169 commit 5ded0ad
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2017-05-28 Barton E. Schaefer <schaefer@zsh.org>

* 41159 (tweaked): Completion/Unix/Command/_ssh: handle "Include"
and "HostName" lines in ~/.ssh/config

2017-05-24 Peter Stephenson <p.stephenson@samsung.com>

* Sebastian: 41146: Src/Modules/db_gdbm.c: be more careful about
Expand Down
28 changes: 17 additions & 11 deletions Completion/Unix/Command/_ssh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

5 comments on commit 5ded0ad

@hdiass
Copy link

@hdiass hdiass commented on 5ded0ad Nov 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can i get this on the MacOS zsh 5.6.2 (x86_64-apple-darwin18.2.0) ?

@danielshahaf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you're asking how to get this patch applied to your zsh installation. The answer to that is, you don't need to do anything; this patch is part of zsh 5.6.2. Does this answer your question? If not, please clarify.

@hdiass
Copy link

@hdiass hdiass commented on 5ded0ad Nov 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange thing is i'm on the version you mentioned and the _ssh_hosts looks like the one before the commit on this thread.

@danielshahaf
Copy link
Member

@danielshahaf danielshahaf commented on 5ded0ad Nov 28, 2018 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hdiass
Copy link

@hdiass hdiass commented on 5ded0ad Nov 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're correct, i've more than one zsh installed. Thanks for the follow up 👍

Please sign in to comment.