sunlei / zsh-ssh

Better host completion for ssh in Zsh.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Autocompletion stopped working with commit 2581ff1

1978ajot opened this issue · comments

Commit 2581ff1 brokes autocompletion (at least for included files).

Here is my patch to fix that issue:

---
 zsh-ssh.zsh | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/zsh-ssh.zsh b/zsh-ssh.zsh
index 342d84d..9a63df8 100644
--- a/zsh-ssh.zsh
+++ b/zsh-ssh.zsh
@@ -8,17 +8,18 @@
 _ssh-host-list() {
   local ssh_config host_list
 
-  ssh_config=$(command awk '
+
+  ssh_config=$(command awk -v PREFIX=$HOME/.ssh/ '
     {
-      if (NF == 2 && tolower($1) == "include")
-        {
-          cmd = "sed -s '\''$G'\'' " $2 " 2> /dev/null"
-          # print cmd
-          while ( (cmd | getline line) > 0 ) {
-            print line
-          }
-          close($2)
+      if (NF == 2 && tolower($1) == "include") {
+        file = PREFIX $2
+        cmd = "sed -s '\''$G'\'' " file " "
+        # print cmd
+        while ( (cmd | getline line) > 0 ) {
+          print line
         }
+        close(file)
+      }
       else {
         print
       }
-- 
2.40.0

commented

Commit 2581ff1 broke relative path references to "include".

Your patch fixed relative path references, but broke absolute path references. I think we need a better solution to this problem.

commented

try bc48f6c.

Works for me. Thanks!

commented

@sunlei I found an edge case where autocompletion doesn't work if there is an Include path with wildcards but no matches are found.

My use case is that I have another python tool to create / delete VMs and when created, an ssh_config file is generated per project in the tool's directory, so something like:

Include ~/tools/overlord/projects/*/ssh_configs/*

However, if I have no current projects then I get errors when I try to autocomplete because no matches are found for the above wildcard.

I think I found a fix which is to include the following in _parse_config_file by adding the following:

# disable no match errors for Include with wildcard statements that don't have matches
unsetopt nomatch

This temporarily disables the error message from the attempt at glob expansion and proceeds to auto-complete based on the rest of the SSH config.

I thought it's too trivial to submit a PR so I'm just mentioning it here. On older versions of this plugin (not sure which ones), this wasn't a problem.