From ffc8aafb2a467b54aa0b4c79330a2f4391c8ea48 Mon Sep 17 00:00:00 2001 From: moqsien Date: Wed, 28 Aug 2024 17:23:30 +0800 Subject: [PATCH] terminal --- internal/installer/installer.go | 5 +++-- internal/installer/locker.go | 5 +++-- internal/terminal/terminal.go | 29 +++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/internal/installer/installer.go b/internal/installer/installer.go index 869d7a2..32a485f 100644 --- a/internal/installer/installer.go +++ b/internal/installer/installer.go @@ -222,8 +222,9 @@ func (i *Installer) Install() { os.Setenv(AddToPathTemporarillyEnvName, "1") i.AddEnvsTemporarilly() - t := terminal.NewPtyTerminal() - t.Run() + // t := terminal.NewPtyTerminal() + // t.Run() + terminal.RunTerminal() } } diff --git a/internal/installer/locker.go b/internal/installer/locker.go index b2fa9a0..c8f4158 100644 --- a/internal/installer/locker.go +++ b/internal/installer/locker.go @@ -117,7 +117,7 @@ func (v *VersionLocker) HookForCdCommand() { if len(v.VersionOfSDKs) == 0 { os.Exit(0) } - t := terminal.NewPtyTerminal() + // t := terminal.NewPtyTerminal() os.Setenv(AddToPathTemporarillyEnvName, "1") for sdkName, versionName := range v.VersionOfSDKs { RemoveGlobalSDKPathTemporarily(sdkName) @@ -125,7 +125,8 @@ func (v *VersionLocker) HookForCdCommand() { // follow the order. ins.AddEnvsTemporarilly() } - t.Run() + // t.Run() + terminal.RunTerminal() } /* diff --git a/internal/terminal/terminal.go b/internal/terminal/terminal.go index 435879b..97e0e12 100644 --- a/internal/terminal/terminal.go +++ b/internal/terminal/terminal.go @@ -3,6 +3,7 @@ package terminal import ( "fmt" "os" + "os/exec" "path/filepath" "runtime" "strings" @@ -113,3 +114,31 @@ func GetTerminalSize() (height, width int, err error) { t := term.NewTerminal() return t.Size() } + +func RunTerminal() { + var command string + if runtime.GOOS == gutils.Windows { + pp, _ := process.NewProcess(int32(os.Getppid())) + command, _ = pp.Name() + if command == "" { + command = "powershell.exe" + } + } else { + command = "/bin/sh" + if shell := os.Getenv("SHELL"); shell != "" { + command = shell + } + } + if runtime.GOOS != gutils.Windows { + os.Setenv(sh.VMDisableEnvName, "111") + } + if command != "" { + cmd := exec.Command(command) + cmd.Env = os.Environ() + cmd.Stdout = os.Stdout + cmd.Stdin = os.Stdin + cmd.Stderr = os.Stderr + cmd.Start() + cmd.Wait() + } +}