Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Dec 19, 2023
1 parent 07b022a commit 61a8f77
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions cmd/carapace/cmd/macros.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(".")
}),
)

Expand Down

0 comments on commit 61a8f77

Please sign in to comment.