From 1d8a32edef37afbc6ad37495d6d737d3146d09e7 Mon Sep 17 00:00:00 2001 From: CatsDeservePets <145048791+CatsDeservePets@users.noreply.github.com> Date: Thu, 5 Nov 2026 23:52:40 +0100 Subject: [PATCH] feat: improve completion for boolean options (#2733) --- complete.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/complete.go b/complete.go index 9cc342ae..a43f67e0 100644 --- a/complete.go +++ b/complete.go @@ -201,6 +201,18 @@ func matchWord(s string, words []string) (matches []compMatch, longest string) { return } +func matchOpt(s string, words []string) (matches []compMatch, longest string) { + matches, longest = matchWord(s, words) + if strings.HasPrefix(s, "no") { + // Show negated options without their prefix in the menu. + // TODO: Update if a future option ever starts with "no". + for i := range matches { + matches[i].name = matches[i].name[2:] + } + } + return +} + func matchList(s string, words []string) (matches []compMatch, longest string) { toks := strings.Split(s, ":") @@ -384,7 +396,7 @@ func completeCmd(s string) (matches []compMatch, longest string) { switch f[0] { case "set": if len(f) == 2 { - matches, longest = matchWord(f[1], gOptWords) + matches, longest = matchOpt(f[1], gOptWords) break } if len(f) != 3 { @@ -420,7 +432,7 @@ func completeCmd(s string) (matches []compMatch, longest string) { break } if len(f) == 3 { - matches, longest = matchWord(f[2], gLocalOptWords) + matches, longest = matchOpt(f[2], gLocalOptWords) break } if len(f) != 4 {