From 2124a2ed1cffe822ba4388f113801319352fd210 Mon Sep 17 00:00:00 2001 From: Wade Bourne Date: Thu, 15 Jun 2023 16:27:55 -0700 Subject: [PATCH] fix bug causing editor to close when ctrl+c pressed in shell --- cmd/templates.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cmd/templates.go b/cmd/templates.go index 7c3f842..f0049f8 100644 --- a/cmd/templates.go +++ b/cmd/templates.go @@ -360,14 +360,22 @@ func openProject(dirName string) { os.Exit(1) } } + cmd := exec.Command("subl", "-p", projPath) - err = exec.Command("subl", "-p", projPath).Run() + // without setsid signals from ctrl+c in shell will be forwarded to the child proc + // causing the editor to exit + cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true} + + err = cmd.Run() if err != nil { fmt.Println("unable to start subl:", err.Error()) os.Exit(1) } } else if editor == "code" || editor == "code-oss" { - err = exec.Command(editor, dirName).Run() + cmd := exec.Command(editor, dirName) + cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true} + + err = cmd.Run() if err != nil { fmt.Println("unable to start vscode:", err.Error()) os.Exit(1)