From 6f924df8ac20765189bc13b314486fbebd44466b Mon Sep 17 00:00:00 2001 From: Vincent Neubauer Date: Thu, 2 Jan 2025 06:29:53 +0000 Subject: [PATCH] Fix/Login Edit Use Editor Env (#706) It is very common to set `$EDITOR` to an terminal editor. To do so, we have to attach the stdin and stdout to interact with it. Otherwise the command would do nothing (when using `.Run()`) as it silently fails or hang the command (using `.Start()`) because it waits forever for input. Also attaching stderr to make debugging easier if someone has a non-compatible or broken `$EDITOR` set. Reviewed-on: https://gitea.com/gitea/tea/pulls/706 Reviewed-by: Lunny Xiao Co-authored-by: Vincent Neubauer Co-committed-by: Vincent Neubauer --- cmd/login/edit.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cmd/login/edit.go b/cmd/login/edit.go index 5f8d284..1fc27cb 100644 --- a/cmd/login/edit.go +++ b/cmd/login/edit.go @@ -4,6 +4,10 @@ package login import ( + "log" + "os" + "os/exec" + "code.gitea.io/tea/cmd/flags" "code.gitea.io/tea/modules/config" @@ -23,5 +27,14 @@ var CmdLoginEdit = cli.Command{ } func runLoginEdit(_ *cli.Context) error { + if e, ok := os.LookupEnv("EDITOR"); ok && e != "" { + cmd := exec.Command(e, config.GetConfigPath()) + cmd.Stdin = os.Stdin + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + if err := cmd.Run(); err != nil { + log.Fatal(err.Error()) + } + } return open.Start(config.GetConfigPath()) }