-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplete.go
More file actions
82 lines (74 loc) · 1.53 KB
/
complete.go
File metadata and controls
82 lines (74 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
// This file implements bash programmable completion.
import (
"fmt"
"strconv"
)
func init() {
help["complete"] = `do bash autocompletion on arguments`
}
// args: $COMP_WORDC $COMP_LINE, e.g.:
// 3 clip play jaz
func (api API) Complete(args []string) (resp, err string) {
// don't crash on panic
defer func() {
e := recover()
if e != nil {
Debug(e)
err = fmt.Sprint(e)
resp = ""
}
}()
// myargs: arguments, without preceeding "clip"
// and only up to the one being completed.
// "" means new word to be started.
myargs := []string{}
idx, _ := strconv.Atoi(args[0])
idx--
//Debug("idx", idx)
//Debug("len", len(args)-2)
myargs = args[2:]
if idx == len(args)-2 {
myargs = append(myargs, "")
}
Debug("complete", myargs, "len", len(myargs))
switch myargs[0] {
default:
return
}
return
}
// Used by "clip -c", invoked by bash completion.
// args:
// word line
// E.g.:
// clip alpha beta<TAB>
// yields args:
// beta clip alpha beta
//func AutoComplete(args []string) {
// if len(args) == 0 {
// return // should not happen
// }
// if len(args) == 1 {
// // fix for word = "" (omitted by bash)
// args = []string{"", args[0], ""}
// }
// word := args[0]
// //cmd := args[1]
// //line := args[2:]
// if len(args) == 3 {
// completeCommands(word)
// return
// }
//}
//
//
//// Auto-complete function for player commands like
//// add ls play ...
//func completeCommands(prefix string) {
// for cmd, _ := range player.command {
// if strings.HasPrefix(cmd, prefix) {
// fmt.Print(cmd, " ")
// }
// }
//}