about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDaniel Shahaf <d.s@daniel.shahaf.name>2016-07-29 17:50:02 +0000
committerDaniel Shahaf <d.s@daniel.shahaf.name>2016-07-31 16:21:32 +0000
commita3b538964127d92352547e8574d07f820aea525f (patch)
tree56a2cae1063b1dd0696cb958fb91833f333f78f9
parent625fe0fce898742ab6f14c5cc3dbfb1a89265a83 (diff)
downloadzsh-a3b538964127d92352547e8574d07f820aea525f.tar.gz
zsh-a3b538964127d92352547e8574d07f820aea525f.tar.xz
zsh-a3b538964127d92352547e8574d07f820aea525f.zip
38967: _hosts: Don't complete wildcard entries from ~/.ssh/known_hosts.
-rw-r--r--ChangeLog3
-rw-r--r--Completion/Unix/Type/_hosts23
2 files changed, 19 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index b2a7a9a5e..b30266ec4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2016-07-31  Daniel Shahaf  <d.s@daniel.shahaf.name>
 
+	* 38967: Completion/Unix/Type/_hosts: Don't complete wildcard
+	entries from ~/.ssh/known_hosts.
+
 	* 38966: Completion/Unix/Command/_subversion: _svnadmin: Complete
 	positional arguments for 'hotcopy', 'setlog', 'setrevprop',
 	'delrevprop'.
diff --git a/Completion/Unix/Type/_hosts b/Completion/Unix/Type/_hosts
index c3133dc68..56540865e 100644
--- a/Completion/Unix/Type/_hosts
+++ b/Completion/Unix/Type/_hosts
@@ -45,13 +45,22 @@ if ! zstyle -a ":completion:${curcontext}:hosts" hosts _hosts; then
 
         # known_hosts syntax supports the host being in the form [hostname]:port
         # The filter below extracts the hostname from lines using this format.
-        khosts=($(for host ($khosts); do
-          if [[ $host =~ "\[(.*)\]:\d*" ]]; then
-            echo $match
-          else
-            echo $host
-          fi
-        done))
+        #
+        # known_hosts syntax supports wildcards.  The filter below removes wildcard
+        # entries.
+        () {
+          local host
+          khosts=()
+          for host; do
+            if [[ $host == *[*?]* ]]; then
+              continue
+            elif [[ $host =~ "\[(.*)\]:\d*" ]]; then
+              khosts+=$match
+            else
+              khosts+=$host
+            fi
+          done
+        } "$khosts[@]"
 
         if [[ -z $useip ]]; then
           khosts=(${${khosts:#(#s)[0-9]##.[0-9]##.[0-9]##.[0-9]##(#e)}:#(#s)[0-9a-f:]##(#e)})