From 3ba00a035c190fab94293079f029611e5bb5ad9c Mon Sep 17 00:00:00 2001 From: gutmet Date: Mon, 10 Dec 2018 17:16:26 +0100 Subject: [PATCH] add OpenInEditor --- goutil.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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)