Skip to content

Commit

Permalink
Refactor shell detection logic to use shellType helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenkumar committed Oct 18, 2024
1 parent 4aeed06 commit 1efb9fa
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 @@ -67,32 +66,33 @@ 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:
shellTypeResult := shellType(shell)
if shellTypeResult == "cmd" {
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), nil
}
return shellTypeResult, nil
}

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

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

func shellType(shell 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 "cmd" // this could be either powershell or cmd, defaulting to cmd
}
}

0 comments on commit 1efb9fa

Please sign in to comment.