zsh-workers
 help / Atom feed
* [PATCH] _ssh_hosts: abort early if in a path
@ 2019-05-27 23:33 Phil Pennock
  2019-05-29 13:57 ` Jun-ichi Takimoto
  0 siblings, 1 reply; 3+ messages in thread
From: Phil Pennock @ 2019-05-27 23:33 UTC (permalink / raw)
  To: zsh-workers

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
those.

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
+    ;;
+esac
+
 # If users-hosts matches, we shouldn't complete anything else.
 if [[ "$IPREFIX" == *@ ]]; then
   _combination -s '[:@]' my-accounts users-hosts "users=${IPREFIX/@}" hosts "$@" && return
-- 
2.21.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] _ssh_hosts: abort early if in a path
  2019-05-27 23:33 [PATCH] _ssh_hosts: abort early if in a path Phil Pennock
@ 2019-05-29 13:57 ` Jun-ichi Takimoto
  2019-05-29 21:50   ` Phil Pennock
  0 siblings, 1 reply; 3+ messages in thread
From: Jun-ichi Takimoto @ 2019-05-29 13:57 UTC (permalink / raw)
  To: zsh-workers


> 2019/05/28 8:33、Phil Pennock <zsh-workers+phil.pennock@spodhuis.org>のメール:
> 
> +case "$PREFIX" in
> +  ( /* | ./* )
> +    return
> +    ;;
> +esac

Isn't it better to "return 1"?

_ssh_hosts (before your patch) does not return 1 even if it can't 
find any matches. Maybe better to fix this also?


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] _ssh_hosts: abort early if in a path
  2019-05-29 13:57 ` Jun-ichi Takimoto
@ 2019-05-29 21:50   ` Phil Pennock
  0 siblings, 0 replies; 3+ messages in thread
From: Phil Pennock @ 2019-05-29 21:50 UTC (permalink / raw)
  To: Jun-ichi Takimoto; +Cc: zsh-workers

On 2019-05-29 at 22:57 +0900, Jun-ichi Takimoto wrote:
> > 2019/05/28 8:33、Phil Pennock <zsh-workers+phil.pennock@spodhuis.org>のメール:
> > 
> > +case "$PREFIX" in
> > +  ( /* | ./* )
> > +    return
> > +    ;;
> > +esac
> 
> Isn't it better to "return 1"?

Doesn't seem to make any difference to the ssh family completions or to
git, but the docs seem to suggest that you're right, and `return 1` is
better.

> _ssh_hosts (before your patch) does not return 1 even if it can't 
> find any matches. Maybe better to fix this also?

If someone else wants to start an audit of the shipped completion
functions and their return statuses, then that's great.  Perhaps there's
some future optimizations which could be made if more of the completion
system cared about return codes.

But for me: the patch I offered (possibly modified to return 1) makes a
significant difference to performance and usability of zsh when copying
files between hosts.  That's the patch I'm offering for consideration:
small; simple to analyse; with clear results.

-Phil

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-27 23:33 [PATCH] _ssh_hosts: abort early if in a path Phil Pennock
2019-05-29 13:57 ` Jun-ichi Takimoto
2019-05-29 21:50   ` Phil Pennock

zsh-workers

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-workers

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


AGPL code for this site: git clone https://public-inbox.org/ public-inbox