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,16 +13,25 @@ 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{}
for _, mg := range completions[0].Groups { f := func(format string, args ...interface{}) { fmt.Fprintf(&output, format, args...) }
mg.remove_common_prefix() n := completions[0].Delegate.NumToRemove
for _, m := range mg.Matches { if n > 0 {
w := m.Word n--
if !mg.NoTrailingSpace { f("COMP_WORDS[%d]=%s\n", n, utils.QuoteStringForSH(completions[0].Delegate.Command))
w += " " f("_command_offset %d\n", n)
} else {
for _, mg := range completions[0].Groups {
mg.remove_common_prefix()
for _, m := range mg.Matches {
w := m.Word
if !mg.NoTrailingSpace {
w += " "
}
f("COMPREPLY+=(%s)\n", utils.QuoteStringForSH(w))
} }
fmt.Fprintln(&output, "COMPREPLY+=("+utils.QuoteStringForSH(w)+")")
} }
} }
// debugf("%#v", output.String())
return []byte(output.String()), nil return []byte(output.String()), nil
} }