From 6243514def648309fdc323f97248869c5893d6ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Untersch=C3=BCtz?= Date: Wed, 28 Oct 2026 11:44:54 +0100 Subject: [PATCH] fix(completion): accept instance-qualified hosts for a bare name in zsh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With several NetBox instances, netssh offers "prod/fsn1-bx1…" for the typed text "fsn1". compadd discarded these matches because they do not start with the typed word, so found nothing. The matcher 'l:|=*' lets zsh accept text before the typed word; netssh has already filtered the candidates. Co-Authored-By: Claude Opus 5.5 --- internal/hook/completion_test.go | 2 +- internal/hook/zsh.go | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/internal/hook/completion_test.go b/internal/hook/completion_test.go index c5f3f14..ea0c37b 100644 --- a/internal/hook/completion_test.go +++ b/internal/hook/completion_test.go @@ -200,7 +200,7 @@ _netssh t.Fatalf("%v\n%s", err, out) } // Directive 36 = NoFileComp|KeepOrder: unsorted host group, no file fallback. - want := "describe cache:Manage the cache\ncompadd -V hosts -X %Bhosts%b -- web01 web:02\n" + want := "describe cache:Manage the cache\ncompadd -V hosts -X %Bhosts%b -M l:|=* -- web01 web:02\n" if string(out) != want { t.Fatalf("got:\n%s\nwant:\n%s", out, want) } diff --git a/internal/hook/zsh.go b/internal/hook/zsh.go index a9db706..79fe95a 100644 --- a/internal/hook/zsh.go +++ b/internal/hook/zsh.go @@ -58,12 +58,13 @@ _netssh() { _describe -t commands 'netssh command' items $nospace && ret=0 fi if (( $#plain )); then + # netssh already filtered the hosts, also by the name after an instance + # prefix: "fsn1" offers "prod/fsn1-…". 'l:|=*' lets zsh accept text + # before the typed word instead of discarding these matches. + local -a group=(-J hosts) # Directive 32: keep the order supplied by netssh. - if (( directive & 32 )); then - compadd -V hosts -X '%Bhosts%b' $nospace -- $plain && ret=0 - else - compadd -J hosts -X '%Bhosts%b' $nospace -- $plain && ret=0 - fi + (( directive & 32 )) && group=(-V hosts) + compadd $group -X '%Bhosts%b' -M 'l:|=*' $nospace -- $plain && ret=0 fi # Directive 4: no file completion as a fallback. if (( ! $#lines && ! (directive & 4) )); then