+// OptionValueComplete completes values for various options
+func OptionValueComplete(inputOpt, input string) (string, []string) {
+ inputOpt = strings.TrimSpace(inputOpt)
+ var suggestions []string
+ localSettings := DefaultLocalSettings()
+ var optionVal interface{}
+ for k, option := range globalSettings {
+ if k == inputOpt {
+ optionVal = option
+ }
+ }
+ for k, option := range localSettings {
+ if k == inputOpt {
+ optionVal = option
+ }
+ }
+
+ switch optionVal.(type) {
+ case bool:
+ if strings.HasPrefix("on", input) {
+ suggestions = append(suggestions, "on")
+ } else if strings.HasPrefix("true", input) {
+ suggestions = append(suggestions, "true")
+ }
+ if strings.HasPrefix("off", input) {
+ suggestions = append(suggestions, "off")
+ } else if strings.HasPrefix("false", input) {
+ suggestions = append(suggestions, "false")
+ }
+ case string:
+ switch inputOpt {
+ case "colorscheme":
+ _, suggestions = ColorschemeComplete(input)
+ case "fileformat":
+ if strings.HasPrefix("unix", input) {
+ suggestions = append(suggestions, "unix")
+ }
+ if strings.HasPrefix("dos", input) {
+ suggestions = append(suggestions, "dos")
+ }
+ case "sucmd":
+ if strings.HasPrefix("sudo", input) {
+ suggestions = append(suggestions, "sudo")
+ }
+ if strings.HasPrefix("doas", input) {
+ suggestions = append(suggestions, "doas")
+ }
+ }
+ }
+
+ var chosen string
+ if len(suggestions) == 1 {
+ chosen = suggestions[0]
+ }
+ return chosen, suggestions
+}
+
+// MakeCompletion registers a function from a plugin for autocomplete commands