9 func FileComplete(input string) (string, []string) {
10 dirs := strings.Split(input, "/")
11 var files []os.FileInfo
14 files, err = ioutil.ReadDir(strings.Join(dirs[:len(dirs)-1], "/"))
16 files, err = ioutil.ReadDir(".")
18 var suggestions []string
20 return "", suggestions
22 for _, f := range files {
27 if strings.HasPrefix(name, dirs[len(dirs)-1]) {
28 suggestions = append(suggestions, name)
33 if len(suggestions) == 1 {
35 chosen = strings.Join(dirs[:len(dirs)-1], "/") + "/" + suggestions[0]
37 chosen = suggestions[0]
41 return chosen, suggestions
44 func CommandComplete(input string) (string, []string) {
45 var suggestions []string
46 for cmd := range commands {
47 if strings.HasPrefix(cmd, input) {
48 suggestions = append(suggestions, cmd)
53 if len(suggestions) == 1 {
54 chosen = suggestions[0]
56 return chosen, suggestions
59 func HelpComplete(input string) (string, []string) {
60 var suggestions []string
62 for _, topic := range helpFiles {
63 if strings.HasPrefix(topic, input) {
65 suggestions = append(suggestions, topic)
70 if len(suggestions) == 1 {
71 chosen = suggestions[0]
73 return chosen, suggestions
76 func OptionComplete(input string) (string, []string) {
77 var suggestions []string
78 for option := range settings {
79 if strings.HasPrefix(option, input) {
80 suggestions = append(suggestions, option)
85 if len(suggestions) == 1 {
86 chosen = suggestions[0]
88 return chosen, suggestions