Skip to content

Commit

Permalink
shell_windows: Detect shell under ssh
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Fanjul authored and praveenkumar committed Oct 18, 2024
1 parent 9f06891 commit f4ccc58
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions pkg/os/shell/shell_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"math"
"os"
"path/filepath"
"strings"
"syscall"
"unsafe"
Expand Down Expand Up @@ -55,6 +54,19 @@ func getNameAndItsPpid(pid uint32) (exefile string, parentid uint32, err error)
return name, pe.ParentProcessID, nil
}

func shellType(shell string, defaultShell string) string {
switch {
case strings.Contains(strings.ToLower(shell), "powershell"):
return "powershell"
case strings.Contains(strings.ToLower(shell), "pwsh"):
return "powershell"
case strings.Contains(strings.ToLower(shell), "cmd"):
return "cmd"
default:
return defaultShell
}
}

func detect() (string, error) {
shell := os.Getenv("SHELL")

Expand All @@ -67,32 +79,20 @@ func detect() (string, error) {
if err != nil {
return "cmd", err // defaulting to cmd
}
switch {
case strings.Contains(strings.ToLower(shell), "powershell"):
return "powershell", nil
case strings.Contains(strings.ToLower(shell), "pwsh"):
return "powershell", nil
case strings.Contains(strings.ToLower(shell), "cmd"):
return "cmd", nil
default:
shell = shellType(shell, "")
if shell == "" {
shell, _, err := getNameAndItsPpid(shellppid)
if err != nil {
return "cmd", err // defaulting to cmd
}
switch {
case strings.Contains(strings.ToLower(shell), "powershell"):
return "powershell", nil
case strings.Contains(strings.ToLower(shell), "cmd"):
return "cmd", nil
default:
return "cmd", nil // this could be either powershell or cmd, defaulting to cmd
}
return shellType(shell, "cmd"), nil
}
return shell, nil
}

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

return filepath.Base(shell), nil
return shellType(shell, "cmd"), nil
}

0 comments on commit f4ccc58

Please sign in to comment.