Skip to content

Commit f4ccc58

Browse files
Alberto Fanjulpraveenkumar
authored andcommitted
shell_windows: Detect shell under ssh
1 parent 9f06891 commit f4ccc58

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

pkg/os/shell/shell_windows.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"math"
66
"os"
7-
"path/filepath"
87
"strings"
98
"syscall"
109
"unsafe"
@@ -55,6 +54,19 @@ func getNameAndItsPpid(pid uint32) (exefile string, parentid uint32, err error)
5554
return name, pe.ParentProcessID, nil
5655
}
5756

57+
func shellType(shell string, defaultShell string) string {
58+
switch {
59+
case strings.Contains(strings.ToLower(shell), "powershell"):
60+
return "powershell"
61+
case strings.Contains(strings.ToLower(shell), "pwsh"):
62+
return "powershell"
63+
case strings.Contains(strings.ToLower(shell), "cmd"):
64+
return "cmd"
65+
default:
66+
return defaultShell
67+
}
68+
}
69+
5870
func detect() (string, error) {
5971
shell := os.Getenv("SHELL")
6072

@@ -67,32 +79,20 @@ func detect() (string, error) {
6779
if err != nil {
6880
return "cmd", err // defaulting to cmd
6981
}
70-
switch {
71-
case strings.Contains(strings.ToLower(shell), "powershell"):
72-
return "powershell", nil
73-
case strings.Contains(strings.ToLower(shell), "pwsh"):
74-
return "powershell", nil
75-
case strings.Contains(strings.ToLower(shell), "cmd"):
76-
return "cmd", nil
77-
default:
82+
shell = shellType(shell, "")
83+
if shell == "" {
7884
shell, _, err := getNameAndItsPpid(shellppid)
7985
if err != nil {
8086
return "cmd", err // defaulting to cmd
8187
}
82-
switch {
83-
case strings.Contains(strings.ToLower(shell), "powershell"):
84-
return "powershell", nil
85-
case strings.Contains(strings.ToLower(shell), "cmd"):
86-
return "cmd", nil
87-
default:
88-
return "cmd", nil // this could be either powershell or cmd, defaulting to cmd
89-
}
88+
return shellType(shell, "cmd"), nil
9089
}
90+
return shell, nil
9191
}
9292

9393
if os.Getenv("__fish_bin_dir") != "" {
9494
return "fish", nil
9595
}
9696

97-
return filepath.Base(shell), nil
97+
return shellType(shell, "cmd"), nil
9898
}

0 commit comments

Comments
 (0)