diff --git a/goutil.go b/goutil.go index 386f95a..c3a5868 100644 --- a/goutil.go +++ b/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 CommandFlagsInit func(s *flag.FlagSet)