add OpenInEditor

This commit is contained in:
gutmet 2018-12-10 17:16:26 +01:00
parent 807c472815
commit 3ba00a035c

View File

@ -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 CommandFlagsInit func(s *flag.FlagSet)