Get delegate based completion working for bash
This commit is contained in:
parent
1dce092ac0
commit
08c697e99a
@ -13,16 +13,25 @@ var _ = fmt.Print
|
||||
|
||||
func bash_output_serializer(completions []*Completions, shell_state map[string]string) ([]byte, error) {
|
||||
output := strings.Builder{}
|
||||
for _, mg := range completions[0].Groups {
|
||||
mg.remove_common_prefix()
|
||||
for _, m := range mg.Matches {
|
||||
w := m.Word
|
||||
if !mg.NoTrailingSpace {
|
||||
w += " "
|
||||
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 {
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user