Skip to content

Commit 2603ff5

Browse files
refactor: strip .exe from shell names
1 parent 401c5b3 commit 2603ff5

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

segment_shell.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package main
22

3+
import "strings"
4+
35
type shell struct {
46
props *properties
57
env environmentInfo
@@ -15,7 +17,8 @@ func (s *shell) string() string {
1517
if err != nil {
1618
return "unknown"
1719
}
18-
return p.Executable()
20+
shell := strings.Replace(p.Executable(), ".exe", "", 1)
21+
return shell
1922
}
2023

2124
func (s *shell) init(props *properties, env environmentInfo) {

segment_shell_test.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,22 @@ func TestWriteCurrentShell(t *testing.T) {
4242
env: env,
4343
props: props,
4444
}
45-
assert.Equal(t, "zsh", s.string())
45+
assert.Equal(t, expected, s.string())
46+
}
47+
48+
func TestWriteCurrentShellWindowsExe(t *testing.T) {
49+
expected := "pwsh"
50+
env := new(MockedEnvironment)
51+
process := new(process)
52+
parentProcess := expected + ".exe"
53+
process.On("Executable", nil).Return(parentProcess)
54+
env.On("getParentProcess", nil).Return(process, nil)
55+
props := &properties{}
56+
s := &shell{
57+
env: env,
58+
props: props,
59+
}
60+
assert.Equal(t, expected, s.string())
4661
}
4762

4863
func TestWriteCurrentShellError(t *testing.T) {

0 commit comments

Comments
 (0)