From f88ef4f9a41db8a42660d53790f1f075cc1bc82b Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Sun, 3 Apr 2016 16:19:21 -0400 Subject: [PATCH] Add shorthand for commands if it is unambiguous --- src/command.go | 20 ++++++++++++++++++-- src/view.go | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/command.go b/src/command.go index 28474361..cfffc22a 100644 --- a/src/command.go +++ b/src/command.go @@ -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": diff --git a/src/view.go b/src/view.go index 6b6f76c7..ae446765 100644 --- a/src/view.go +++ b/src/view.go @@ -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