Merge pull request #3370 from Zireael/fix/git-bash-shell-detection-on-windows

fix: detect Git Bash/WSL/MSYS2 shell on Windows (non-interactive-env hook)
This commit is contained in:
YeonGyu-Kim
2026-05-21 12:58:48 +09:00
committed by GitHub
+16 -9
View File
@@ -5,12 +5,14 @@ export type ShellType = "unix" | "powershell" | "cmd" | "csh"
* *
* Detection priority: * Detection priority:
* 1. SHELL env var → Unix shell (explicit user choice takes precedence) * 1. SHELL env var → Unix shell (explicit user choice takes precedence)
* 2. PSModulePath → PowerShell * 2. Unix shell indicators on Windows → Git Bash, WSL, MSYS2
* 3. Platform fallback → win32: cmd, others: unix * 3. PSModulePath → PowerShell
* 4. Platform fallback → win32: cmd, others: unix
* *
* Note: SHELL is checked before PSModulePath because on Windows, PSModulePath * Note: Step 2 is scoped to Windows only because PSModulePath is always set
* is always set by the system even when the active shell is Git Bash or WSL. * on Windows regardless of the active shell. Indicators are deliberately
* An explicit SHELL variable indicates the user's chosen shell overrides that. * specific (BASH_VERSION, MSYSTEM, WSL_DISTRO_NAME) — TERM is excluded
* because some PowerShell users set it manually.
*/ */
export function detectShellType(): ShellType { export function detectShellType(): ShellType {
if (process.env.SHELL) { if (process.env.SHELL) {
@@ -21,10 +23,15 @@ export function detectShellType(): ShellType {
return "unix" return "unix"
} }
// Git Bash on Windows sets MSYSTEM (e.g. "MINGW64", "MINGW32", "MSYS") // On Windows, detect Unix-compatible shells (Git Bash, WSL, MSYS2).
// even when SHELL is not set. Detect this before PSModulePath which is // PSModulePath is always set on Windows, so we must check these BEFORE it.
// always present on Windows regardless of the active shell. // Indicators are shell-specific — no broad signals like TERM.
if (process.env.MSYSTEM) { if (
process.platform === "win32" &&
(process.env.BASH_VERSION ||
process.env.MSYSTEM ||
process.env.WSL_DISTRO_NAME)
) {
return "unix" return "unix"
} }