-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
util.go
38 lines (30 loc) · 590 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"errors"
"log"
"os"
"os/exec"
"strings"
)
var logFlag = false
func logPrintln(v ...interface{}) {
if logFlag {
log.Println(v)
}
}
func runEditor(filename string) error {
editor := os.Getenv("EDITOR")
logPrintln("$EDITOR", editor)
if editor == "" {
return errors.New("Set $EDITOR")
}
splitted := strings.Split(editor, " ")
logPrintln("splitted: %#v\n", splitted)
cname := splitted[0]
args := splitted[1:]
args = append(args, filename)
cmd := exec.Command(cname, args[:]...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
return cmd.Run()
}