From 998dbde2aa469c03061ce0a050565adc9c639dfe Mon Sep 17 00:00:00 2001 From: Zireael <3856578+Zireael@users.noreply.github.com> Date: Mon, 13 Apr 2026 01:30:53 +0200 Subject: [PATCH] fix: detect Git Bash/WSL/MSYS2 shell on Windows before PSModulePath On Windows, PSModulePath is always set by the system even when the active shell is Git Bash, WSL, or MSYS2. detectShellType() returned 'powershell' in these cases, causing the non-interactive-env hook to prepend PowerShell $env: syntax which Git Bash cannot parse. Adds checks for TERM, BASH_VERSION, MSYSTEM, and WSL_DISTRO_NAME before the PSModulePath check to correctly identify Unix shells. Fixes #3366 --- src/shared/shell-env.ts | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/shared/shell-env.ts b/src/shared/shell-env.ts index d34ee3254..6d5a2190b 100644 --- a/src/shared/shell-env.ts +++ b/src/shared/shell-env.ts @@ -5,12 +5,14 @@ export type ShellType = "unix" | "powershell" | "cmd" | "csh" * * Detection priority: * 1. SHELL env var → Unix shell (explicit user choice takes precedence) - * 2. PSModulePath → PowerShell - * 3. Platform fallback → win32: cmd, others: unix + * 2. Unix shell indicators on Windows → Git Bash, WSL, MSYS2 + * 3. PSModulePath → PowerShell + * 4. Platform fallback → win32: cmd, others: unix * - * Note: SHELL is checked before PSModulePath because on Windows, PSModulePath - * is always set by the system even when the active shell is Git Bash or WSL. - * An explicit SHELL variable indicates the user's chosen shell overrides that. + * Note: Step 2 is scoped to Windows only because PSModulePath is always set + * on Windows regardless of the active shell. Indicators are deliberately + * specific (BASH_VERSION, MSYSTEM, WSL_DISTRO_NAME) — TERM is excluded + * because some PowerShell users set it manually. */ export function detectShellType(): ShellType { if (process.env.SHELL) { @@ -21,6 +23,18 @@ export function detectShellType(): ShellType { return "unix" } + // On Windows, detect Unix-compatible shells (Git Bash, WSL, MSYS2). + // PSModulePath is always set on Windows, so we must check these BEFORE it. + // Indicators are shell-specific — no broad signals like TERM. + if ( + process.platform === "win32" && + (process.env.BASH_VERSION || + process.env.MSYSTEM || + process.env.WSL_DISTRO_NAME) + ) { + return "unix" + } + if (process.env.PSModulePath) { return "powershell" }