From 61a8f77440a4723157bf4f907926ff44db0cacb4 Mon Sep 17 00:00:00 2001 From: rsteube Date: Tue, 19 Dec 2023 23:46:28 +0100 Subject: [PATCH] tmp --- cmd/carapace/cmd/macros.go | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/cmd/carapace/cmd/macros.go b/cmd/carapace/cmd/macros.go index 11c0e72610..26564f569e 100644 --- a/cmd/carapace/cmd/macros.go +++ b/cmd/carapace/cmd/macros.go @@ -34,18 +34,28 @@ func init() { macrosCmd.Flags().SetInterspersed(false) carapace.Gen(macrosCmd).PositionalCompletion( - carapace.ActionExecCommand("carapace", "--macros")(func(output []byte) carapace.Action { - lines := strings.Split(string(output), "\n") + carapace.ActionMultiPartsN("(", 2, func(c carapace.Context) carapace.Action { + switch len(c.Parts) { + case 0: + return carapace.ActionExecCommand("carapace", "--macros")(func(output []byte) carapace.Action { + lines := strings.Split(string(output), "\n") - vals := make([]string, 0) - for _, line := range lines[:len(lines)-1] { - if fields := strings.Fields(line); len(fields) > 1 { - vals = append(vals, fields[0], strings.Join(fields[1:], " ")) - } else { - vals = append(vals, fields[0], "") + vals := make([]string, 0) + for _, line := range lines[:len(lines)-1] { + if fields := strings.Fields(line); len(fields) > 1 { + vals = append(vals, fields[0], strings.Join(fields[1:], " ")) + } else { + vals = append(vals, fields[0], "") + } + } + return carapace.ActionValuesDescribed(vals...).Invoke(carapace.Context{}).ToMultiPartsA(".") + }) + default: + if m, ok := actions.MacroMap[c.Parts[0]]; ok { + return carapace.ActionValues(m.Signature() + ")") } + return carapace.ActionValues(")") } - return carapace.ActionValuesDescribed(vals...).Invoke(carapace.Context{}).ToMultiPartsA(".") }), )