9 // This file is meant (for now) for autocompletion in command mode, not
10 // while coding. This helps micro autocomplete commands and then filenames
11 // for example with `vsplit filename`.
13 // FileComplete autocompletes filenames
14 func FileComplete(input string) (string, []string) {
15 dirs := strings.Split(input, "/")
16 var files []os.FileInfo
19 files, err = ioutil.ReadDir(strings.Join(dirs[:len(dirs)-1], "/"))
21 files, err = ioutil.ReadDir(".")
23 var suggestions []string
25 return "", suggestions
27 for _, f := range files {
32 if strings.HasPrefix(name, dirs[len(dirs)-1]) {
33 suggestions = append(suggestions, name)
38 if len(suggestions) == 1 {
40 chosen = strings.Join(dirs[:len(dirs)-1], "/") + "/" + suggestions[0]
42 chosen = suggestions[0]
46 return chosen, suggestions
49 // CommandComplete autocompletes commands
50 func CommandComplete(input string) (string, []string) {
51 var suggestions []string
52 for cmd := range commands {
53 if strings.HasPrefix(cmd, input) {
54 suggestions = append(suggestions, cmd)
59 if len(suggestions) == 1 {
60 chosen = suggestions[0]
62 return chosen, suggestions
65 // HelpComplete autocompletes help topics
66 func HelpComplete(input string) (string, []string) {
67 var suggestions []string
69 for _, topic := range helpFiles {
70 if strings.HasPrefix(topic, input) {
72 suggestions = append(suggestions, topic)
77 if len(suggestions) == 1 {
78 chosen = suggestions[0]
80 return chosen, suggestions
83 // OptionComplete autocompletes options
84 func OptionComplete(input string) (string, []string) {
85 var suggestions []string
86 for option := range settings {
87 if strings.HasPrefix(option, input) {
88 suggestions = append(suggestions, option)
93 if len(suggestions) == 1 {
94 chosen = suggestions[0]
96 return chosen, suggestions