Get delegate based completion working for bash

This commit is contained in:
Kovid Goyal 2022-09-19 19:07:46 +05:30
parent 1dce092ac0
commit 08c697e99a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -13,6 +13,13 @@ var _ = fmt.Print
func bash_output_serializer(completions []*Completions, shell_state map[string]string) ([]byte, error) { func bash_output_serializer(completions []*Completions, shell_state map[string]string) ([]byte, error) {
output := strings.Builder{} output := strings.Builder{}
f := func(format string, args ...interface{}) { fmt.Fprintf(&output, format, args...) }
n := completions[0].Delegate.NumToRemove
if n > 0 {
n--
f("COMP_WORDS[%d]=%s\n", n, utils.QuoteStringForSH(completions[0].Delegate.Command))
f("_command_offset %d\n", n)
} else {
for _, mg := range completions[0].Groups { for _, mg := range completions[0].Groups {
mg.remove_common_prefix() mg.remove_common_prefix()
for _, m := range mg.Matches { for _, m := range mg.Matches {
@ -20,9 +27,11 @@ func bash_output_serializer(completions []*Completions, shell_state map[string]s
if !mg.NoTrailingSpace { if !mg.NoTrailingSpace {
w += " " w += " "
} }
fmt.Fprintln(&output, "COMPREPLY+=("+utils.QuoteStringForSH(w)+")") f("COMPREPLY+=(%s)\n", utils.QuoteStringForSH(w))
} }
} }
}
// debugf("%#v", output.String())
return []byte(output.String()), nil return []byte(output.String()), nil
} }