Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: patch for ssh completion
On 5 Mar 2017, d.s@xxxxxxxxxxxxxxxxxx wrote:
> Jeremy — have you seen my review (quoted below)? Would you be able to
> revise the patch to address these points, at least the first two?
>
> Process-wise, patches that apply to latest master are preferred, but
> _ssh hasn't been changed since 5.3.1 so that's okay.
>
> Cheers,
>
> Daniel
I might have a cleaner patch for this which doesn't rely
on external commands. It also handles the case of the relative
path for a user's .ssh directory, although it doesn't attempt to
deal with relative include directives in /etc/ssh. It will
continue to read included files recursively, either from the
user's .ssh directory or via absolute paths. I figured this was
the most common use case, so didn't attempt to deal with /etc/ssh
since it might not be in a standard location depending on how ssh
was compiled.
I also wasn't sure if certain shell options should be
assumed for these completion functions. I am assuming MULTIOS in
this particular example for the included file array to be read
correctly. I tried to follow the existing line reading logic
already present in _ssh_hosts for weeding out the include
directives.
--- Completion/Unix/Command/_ssh.orig 2016-11-25 14:24:09.000000000 -0600
+++ Completion/Unix/Command/_ssh 2017-03-29 17:20:56.508325833 -0500
@@ -1,5 +1,7 @@
#compdef ssh slogin=ssh scp ssh-add ssh-agent ssh-keygen sftp ssh-copy-id
+local -a config_includes
+
# TODO: sshd, ssh-keyscan, ssh-keysign
_ssh () {
@@ -662,6 +664,27 @@
_combination -s '[:@]' my-accounts users-hosts users "$@"
}
+_ssh_includes () {
+ local key includes
+ if [[ -r $@ ]]; then
+ config_includes+=("$@")
+ else
+ return 1
+ fi
+
+ while IFS=$'=\t ' read -r key includes; do
+ if [[ "$key" == (#i)include ]]; then
+ if [[ ${includes[1]} == / ]]; then
+ _ssh_includes $includes
+ else
+ _ssh_includes $HOME/.ssh/$includes
+ fi
+ fi
+ done < "$@"
+
+ return 0
+}
+
_ssh_hosts () {
local -a config_hosts
local config
@@ -679,7 +702,7 @@
else
config="$HOME/.ssh/config"
fi
- if [[ -r $config ]]; then
+ if _ssh_includes $config; then
local key hosts host
while IFS=$'=\t ' read -r key hosts; do
if [[ "$key" == (#i)host ]]; then
@@ -690,7 +713,7 @@
esac
done
fi
- done < "$config"
+ done < ${config_includes}
if (( ${#config_hosts} )); then
_wanted hosts expl 'remote host name' \
compadd -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' "$@" $config_hosts
--
Mark Nipper
nipsy@xxxxxxxxxxxx (XMPP)
-
Spelling mistakes left as an exercise for the reader.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author