diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6b87c77c04..7cdf586358 100755 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,7 +36,7 @@ jobs: strategy: matrix: go-version: - - 1.23.7 + - 1.23.8 sys: - {os: ubuntu-latest} - {os: macos-13, shell: zsh} diff --git a/go.mod b/go.mod index d83833829c..2175443abd 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/ActiveState/cli -go 1.23.7 +go 1.23.8 require ( github.com/99designs/gqlgen v0.17.54 diff --git a/internal/subshell/subshell.go b/internal/subshell/subshell.go index 8844de8e69..f547a1b865 100644 --- a/internal/subshell/subshell.go +++ b/internal/subshell/subshell.go @@ -251,6 +251,7 @@ func detectShellParent() string { multilog.Error("Failed to get parent process: %s", errs.JoinMessage(err)) } + shell := "" for p != nil && p.Pid != 0 { name, err := p.Name() if err == nil { @@ -258,11 +259,19 @@ func detectShellParent() string { name = path.Base(name) } if supportedShellName(name) { - return name + if runtime.GOOS == "darwin" && name == bash.Name && shell == "" { + // The installer starts State Tool after installing it. The user typically invokes the + // installer using the one-line shell command. The one-liner tends to end up in bash, + // which is often not the user's default on macOS. Try looking one level up for the + // correct shell. + shell = name + } else { + return name + } } } p, _ = p.Parent() } - return "" + return shell } diff --git a/internal/subshell/subshell_darwin.go b/internal/subshell/subshell_darwin.go new file mode 100644 index 0000000000..2a96301e08 --- /dev/null +++ b/internal/subshell/subshell_darwin.go @@ -0,0 +1,34 @@ +//go:build darwin +// +build darwin + +package subshell + +import ( + "strings" + + "github.com/ActiveState/cli/internal/subshell/bash" + "github.com/ActiveState/cli/internal/subshell/fish" + "github.com/ActiveState/cli/internal/subshell/tcsh" + "github.com/ActiveState/cli/internal/subshell/zsh" +) + +var supportedShells = []SubShell{ + &bash.SubShell{}, + &zsh.SubShell{}, + &tcsh.SubShell{}, + &fish.SubShell{}, +} + +const ( + SHELL_ENV_VAR = "SHELL" + OS_DEFAULT = "zsh" +) + +func supportedShellName(filename string) bool { + for _, subshell := range supportedShells { + if strings.EqualFold(filename, subshell.Shell()) { + return true + } + } + return false +} diff --git a/internal/subshell/subshell_lin_mac.go b/internal/subshell/subshell_linux.go similarity index 94% rename from internal/subshell/subshell_lin_mac.go rename to internal/subshell/subshell_linux.go index 9a666e16cb..8b4bf1563f 100644 --- a/internal/subshell/subshell_lin_mac.go +++ b/internal/subshell/subshell_linux.go @@ -1,5 +1,5 @@ -//go:build !windows -// +build !windows +//go:build linux +// +build linux package subshell