DetectWindowsShell returns the shell binary and argument prefix for Windows. It prefers PowerShell (resolved via LookPath, which returns an absolute path), falling back to cmd.exe via [WindowsCmdExe].
()
| 49 | // It prefers PowerShell (resolved via LookPath, which returns an absolute path), |
| 50 | // falling back to cmd.exe via [WindowsCmdExe]. |
| 51 | func DetectWindowsShell() (shell string, argsPrefix []string) { |
| 52 | powershellArgs := []string{"-NoProfile", "-NonInteractive", "-Command"} |
| 53 | for _, ps := range []string{"pwsh.exe", "powershell.exe"} { |
| 54 | if path, err := exec.LookPath(ps); err == nil { |
| 55 | return path, powershellArgs |
| 56 | } |
| 57 | } |
| 58 | return WindowsCmdExe(), []string{"/C"} |
| 59 | } |
| 60 | |
| 61 | // DetectUnixShell returns the user's shell from the SHELL environment variable, |
| 62 | // falling back to /bin/sh. |