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

Re: patch for ssh completion



On 29 Mar 2017, Daniel Shahaf wrote:
> Mark Nipper wrote on Wed, Mar 29, 2017 at 18:11:01 -0500:
> > 	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.
> 
> Completions options are run with the options from ${_comp_options} (in
> compinit) in effect; you need an explicit «setopt localoptions multios»
> in this case.
> 
> (@workers feel free to review/apply the patch; I might if I have time,
> but I can't promise)

	I assume putting that into that one function then would
be the correct way to set that.  Added that to the patch:

--- Completion/Unix/Command/_ssh.orig	2016-11-25 14:24:09.000000000 -0600
+++ Completion/Unix/Command/_ssh	2017-03-30 08:53:03.103396162 -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,7 +664,29 @@
   _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 () {
+  setopt localoptions multios
   local -a config_hosts
   local config
   integer ind
@@ -679,7 +703,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 +714,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)
-
¸.·´¯`·.´¯`·.¸¸.·´¯`·.¸><(((º>



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