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

[PATCH] _ssh_hosts: abort early if in a path

The SSH hosts completion is often used in a context where a host or a
file is being matched; with host completion happening first, there can
be a lot of work parsing complex SSH configs and thus that can be slow.

Assuming that for the purposes of SSH, no hostname starts `./` or `/`,
abort early on trying to complete a hostname which starts with one of

UNC paths shouldn't be an issue for SSH, I don't _think_.
 Completion/Unix/Type/_ssh_hosts | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/Completion/Unix/Type/_ssh_hosts b/Completion/Unix/Type/_ssh_hosts
index e20142cfd..7e40f3fa7 100644
--- a/Completion/Unix/Type/_ssh_hosts
+++ b/Completion/Unix/Type/_ssh_hosts
@@ -4,6 +4,15 @@ local -a config_hosts
 local config
 integer ind
+# If it looks like a path, it's not a host for our purposes, abort early so
+# that combined path+host matching can more efficiently deal with local
+# paths.
+case "$PREFIX" in
+  ( /* | ./* )
+    return
+    ;;
 # If users-hosts matches, we shouldn't complete anything else.
 if [[ "$IPREFIX" == *@ ]]; then
   _combination -s '[:@]' my-accounts users-hosts "users=${IPREFIX/@}" hosts "$@" && return

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