aboutsummaryrefslogtreecommitdiffstats
path: root/commands/prompt.go
diff options
context:
space:
mode:
Diffstat (limited to 'commands/prompt.go')
-rw-r--r--commands/prompt.go56
1 files changed, 3 insertions, 53 deletions
diff --git a/commands/prompt.go b/commands/prompt.go
index dd259c30..d791f7a9 100644
--- a/commands/prompt.go
+++ b/commands/prompt.go
@@ -1,8 +1,6 @@
package commands
import (
- "strings"
-
"git.sr.ht/~rjarry/go-opt"
"git.sr.ht/~rjarry/aerc/app"
@@ -10,7 +8,7 @@ import (
type Prompt struct {
Text string `opt:"text"`
- Cmd []string `opt:"..."`
+ Cmd []string `opt:"..." complete:"CompleteCommand"`
}
func init() {
@@ -21,56 +19,8 @@ func (Prompt) Aliases() []string {
return []string{"prompt"}
}
-func (Prompt) Complete(args []string) []string {
- argc := len(args)
- if argc == 0 {
- return nil
- }
- hascommand := argc > 2
- if argc == 1 {
- args = append(args, "")
- }
-
- cmd := GlobalCommands.ByName(args[1])
- var cs []string
- if cmd != nil {
- cs = cmd.Complete(args[2:])
- hascommand = true
- } else {
- if hascommand {
- return nil
- }
- cs = GlobalCommands.Names()
- }
- if cs == nil {
- return nil
- }
-
- var b strings.Builder
- // it seems '' quoting is enough
- // to keep quoted arguments in one piece
- b.WriteRune('\'')
- b.WriteString(args[0])
- b.WriteRune('\'')
- b.WriteRune(' ')
- if hascommand {
- b.WriteString(args[1])
- b.WriteRune(' ')
- }
-
- src := b.String()
- b.Reset()
-
- rs := make([]string, 0, len(cs))
- for _, c := range cs {
- b.WriteString(src)
- b.WriteString(c)
-
- rs = append(rs, b.String())
- b.Reset()
- }
-
- return rs
+func (*Prompt) CompleteCommand(arg string) []string {
+ return CompletionFromList(GlobalCommands.Names(), arg)
}
func (p Prompt) Execute(args []string) error {