Skip to content

Commit faaba18

Browse files
authored
Merge pull request #3672 from ActiveState/mitchell/dx-3248
subshell.DetectShell should default to zsh on macOS.
2 parents f342fee + 461eccd commit faaba18

File tree

5 files changed

+49
-6
lines changed

5 files changed

+49
-6
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
strategy:
3737
matrix:
3838
go-version:
39-
- 1.23.7
39+
- 1.23.8
4040
sys:
4141
- {os: ubuntu-latest}
4242
- {os: macos-13, shell: zsh}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/ActiveState/cli
22

3-
go 1.23.7
3+
go 1.23.8
44

55
require (
66
github.com/99designs/gqlgen v0.17.54

internal/subshell/subshell.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,18 +251,27 @@ func detectShellParent() string {
251251
multilog.Error("Failed to get parent process: %s", errs.JoinMessage(err))
252252
}
253253

254+
shell := ""
254255
for p != nil && p.Pid != 0 {
255256
name, err := p.Name()
256257
if err == nil {
257258
if strings.Contains(name, string(filepath.Separator)) {
258259
name = path.Base(name)
259260
}
260261
if supportedShellName(name) {
261-
return name
262+
if runtime.GOOS == "darwin" && name == bash.Name && shell == "" {
263+
// The installer starts State Tool after installing it. The user typically invokes the
264+
// installer using the one-line shell command. The one-liner tends to end up in bash,
265+
// which is often not the user's default on macOS. Try looking one level up for the
266+
// correct shell.
267+
shell = name
268+
} else {
269+
return name
270+
}
262271
}
263272
}
264273
p, _ = p.Parent()
265274
}
266275

267-
return ""
276+
return shell
268277
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//go:build darwin
2+
// +build darwin
3+
4+
package subshell
5+
6+
import (
7+
"strings"
8+
9+
"github.com/ActiveState/cli/internal/subshell/bash"
10+
"github.com/ActiveState/cli/internal/subshell/fish"
11+
"github.com/ActiveState/cli/internal/subshell/tcsh"
12+
"github.com/ActiveState/cli/internal/subshell/zsh"
13+
)
14+
15+
var supportedShells = []SubShell{
16+
&bash.SubShell{},
17+
&zsh.SubShell{},
18+
&tcsh.SubShell{},
19+
&fish.SubShell{},
20+
}
21+
22+
const (
23+
SHELL_ENV_VAR = "SHELL"
24+
OS_DEFAULT = "zsh"
25+
)
26+
27+
func supportedShellName(filename string) bool {
28+
for _, subshell := range supportedShells {
29+
if strings.EqualFold(filename, subshell.Shell()) {
30+
return true
31+
}
32+
}
33+
return false
34+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build !windows
2-
// +build !windows
1+
//go:build linux
2+
// +build linux
33

44
package subshell
55

0 commit comments

Comments
 (0)