add OpenInEditor
This commit is contained in:
parent
807c472815
commit
3ba00a035c
20
goutil.go
20
goutil.go
|
@ -149,6 +149,26 @@ func OpenInDefaultApp(filename string, wait bool) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func OpenInEditor(filename string, wait bool) error {
|
||||||
|
var err error
|
||||||
|
goos := runtime.GOOS
|
||||||
|
if ed := os.Getenv("EDITOR"); ed != "" {
|
||||||
|
cmd := exec.Command(ed, filename)
|
||||||
|
cmd.Env = os.Environ()
|
||||||
|
if wait {
|
||||||
|
err = cmd.Run()
|
||||||
|
if goos == "windows" {
|
||||||
|
AskFor("Press Enter when you're done")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = cmd.Start()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = errors.New("EDITOR not set in environment")
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
type CommandFunc func(args []string) error
|
type CommandFunc func(args []string) error
|
||||||
|
|
||||||
type CommandFlagsInit func(s *flag.FlagSet)
|
type CommandFlagsInit func(s *flag.FlagSet)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user