readline: Automatically do word completion based on history

This commit is contained in:
Kovid Goyal
2023-03-07 16:44:02 +05:30
parent 4cef83ffd0
commit 0e73c01093
5 changed files with 85 additions and 5 deletions

View File

@@ -560,18 +560,18 @@ func (self *Command) Exec(args ...string) {
}
func (self *Command) GetCompletions(argv []string, init_completions func(*Completions)) *Completions {
ans := Completions{Groups: make([]*MatchGroup, 0, 4)}
ans := NewCompletions()
if init_completions != nil {
init_completions(&ans)
init_completions(ans)
}
if len(argv) > 0 {
exe := argv[0]
cmd := self.FindSubCommand(exe)
if cmd != nil {
if cmd.ParseArgsForCompletion != nil {
cmd.ParseArgsForCompletion(cmd, argv[1:], &ans)
cmd.ParseArgsForCompletion(cmd, argv[1:], ans)
} else {
completion_parse_args(cmd, argv[1:], &ans)
completion_parse_args(cmd, argv[1:], ans)
}
}
}
@@ -582,5 +582,5 @@ func (self *Command) GetCompletions(argv []string, init_completions func(*Comple
}
}
ans.Groups = non_empty_groups
return &ans
return ans
}