]> git.lizzy.rs Git - micro.git/commitdiff
Add shorthand for commands if it is unambiguous
authorZachary Yedidia <zyedidia@gmail.com>
Sun, 3 Apr 2016 20:19:21 +0000 (16:19 -0400)
committerZachary Yedidia <zyedidia@gmail.com>
Sun, 3 Apr 2016 20:19:21 +0000 (16:19 -0400)
src/command.go
src/view.go

index 284743618f1cae6a677b35737f3f29a514253966..cfffc22a6660c5038eb575b4211fb2eab0c3d460 100644 (file)
@@ -7,9 +7,25 @@ import (
 
 // HandleCommand handles input from the user
 func HandleCommand(input string, view *View) {
-       cmd := strings.Split(input, " ")[0]
+       inputCmd := strings.Split(input, " ")[0]
        args := strings.Split(input, " ")[1:]
-       switch cmd {
+
+       commands := []string{"set", "quit", "save"}
+
+       i := 0
+       cmd := inputCmd
+
+       for _, c := range commands {
+               if strings.HasPrefix(c, inputCmd) {
+                       i++
+                       cmd = c
+               }
+       }
+       if i == 1 {
+               inputCmd = cmd
+       }
+
+       switch inputCmd {
        case "set":
                SetOption(view, args)
        case "quit":
index 6b6f76c759fa40bd6f9efcaf1b5a762a00bd1330..ae446765eea052e9a32c79e2c733500efcb9a067 100644 (file)
@@ -217,6 +217,7 @@ func (v *View) Save() {
        if err != nil {
                messenger.Error(err.Error())
        }
+       messenger.Message("Saved " + v.buf.path)
 }
 
 // Copy the selection to the system clipboard