From 671a188802631ab45d551ab8a6c02611dc9fcff8 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Tue, 24 Mar 2020 10:10:44 -0400 Subject: [PATCH] Support +LINE:COL flag syntax for cursor pos Closes #1566 --- cmd/micro/micro.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/cmd/micro/micro.go b/cmd/micro/micro.go index 966f252c..06024975 100644 --- a/cmd/micro/micro.go +++ b/cmd/micro/micro.go @@ -5,6 +5,7 @@ import ( "fmt" "io/ioutil" "os" + "regexp" "runtime" "sort" "time" @@ -44,6 +45,7 @@ func InitFlags() { fmt.Println("-config-dir dir") fmt.Println(" \tSpecify a custom location for the configuration directory") fmt.Println("[FILE]:LINE:COL") + fmt.Println("+LINE:COL") fmt.Println(" \tSpecify a line and column to start the cursor at when opening a buffer") fmt.Println("-options") fmt.Println(" \tShow all option help") @@ -152,11 +154,27 @@ func LoadInput() []*buffer.Buffer { btype = buffer.BTStdout } - if len(args) > 0 { + files := make([]string, 0, len(args)) + flagStartPos := "" + flagr := regexp.MustCompile(`^\+\d+(:\d+)?$`) + for _, a := range args { + if flagr.MatchString(a) { + flagStartPos = a[1:] + } else { + if flagStartPos != "" { + files = append(files, a+":"+flagStartPos) + flagStartPos = "" + } else { + files = append(files, a) + } + } + } + + if len(files) > 0 { // Option 1 // We go through each file and load it - for i := 0; i < len(args); i++ { - buf, err := buffer.NewBufferFromFile(args[i], btype) + for i := 0; i < len(files); i++ { + buf, err := buffer.NewBufferFromFile(files[i], btype) if err != nil { screen.TermMessage(err) continue