Skip to content

Commit

Permalink
terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
moqsien committed Aug 28, 2024
1 parent 088cca4 commit ffc8aaf
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
5 changes: 3 additions & 2 deletions internal/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
5 changes: 3 additions & 2 deletions internal/installer/locker.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,16 @@ 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)
ins := NewInstaller(sdkName, versionName, "", download.Item{})
// follow the order.
ins.AddEnvsTemporarilly()
}
t.Run()
// t.Run()
terminal.RunTerminal()
}

/*
Expand Down
29 changes: 29 additions & 0 deletions internal/terminal/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package terminal
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
Expand Down Expand Up @@ -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()
}
}

0 comments on commit ffc8aaf

Please sign in to comment.