From c72c03f68a2ec50785e65f8755c0dead32fd7eb5 Mon Sep 17 00:00:00 2001 From: anthonykim1 Date: Tue, 2 Dec 2025 11:11:51 -0800 Subject: [PATCH 1/3] Fix command prompt shell startup broken --- src/features/terminal/shells/cmd/cmdStartup.ts | 9 ++++++++- src/features/terminal/terminalManager.ts | 6 ++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/features/terminal/shells/cmd/cmdStartup.ts b/src/features/terminal/shells/cmd/cmdStartup.ts index 3b542ff4..cc23d170 100644 --- a/src/features/terminal/shells/cmd/cmdStartup.ts +++ b/src/features/terminal/shells/cmd/cmdStartup.ts @@ -208,12 +208,12 @@ async function setupCmdStartup(cmdFiles: CmdFilePaths, key: string): Promise Date: Tue, 2 Dec 2025 15:29:25 -0800 Subject: [PATCH 2/3] add shellIntegrationSupportedShells, revert cmdStartup.ts --- .../terminal/shells/cmd/cmdStartup.ts | 9 +------ .../terminal/shells/common/shellUtils.ts | 20 ++++++++++++++ src/features/terminal/terminalManager.ts | 27 ++++++++++--------- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/features/terminal/shells/cmd/cmdStartup.ts b/src/features/terminal/shells/cmd/cmdStartup.ts index cc23d170..3b542ff4 100644 --- a/src/features/terminal/shells/cmd/cmdStartup.ts +++ b/src/features/terminal/shells/cmd/cmdStartup.ts @@ -208,12 +208,12 @@ async function setupCmdStartup(cmdFiles: CmdFilePaths, key: string): Promise { await persistentState.set(SHELL_INTEGRATION_STATE_KEY, shellIntegrationEnabled); return shellIntegrationEnabled; } + +// Shells that support shell integration way of environment activation. +// CMD is not listed here, but we still want to support activation via profile modification. +export const shellIntegrationSupportedShells = [ + ShellConstants.PWSH, + ShellConstants.BASH, + ShellConstants.GITBASH, + ShellConstants.FISH, + ShellConstants.ZSH, +]; + +/** + * Determines whether profile-based activation should be used instead of shell integration. + * Profile activation is preferred when: + * - Running in WSL + * - The shell type doesn't support shell integration (e.g., cmd) + */ +export function shouldUseProfileActivation(shellType: string): boolean { + return isWsl() || !shellIntegrationSupportedShells.includes(shellType); +} diff --git a/src/features/terminal/terminalManager.ts b/src/features/terminal/terminalManager.ts index 4b8e1759..394cc8db 100644 --- a/src/features/terminal/terminalManager.ts +++ b/src/features/terminal/terminalManager.ts @@ -16,7 +16,12 @@ import { getConfiguration, onDidChangeConfiguration } from '../../common/workspa import { isActivatableEnvironment } from '../common/activation'; import { identifyTerminalShell } from '../common/shellDetector'; import { getPythonApi } from '../pythonApi'; -import { getShellIntegrationEnabledCache, isWsl, shellIntegrationForActiveTerminal } from './shells/common/shellUtils'; +import { + getShellIntegrationEnabledCache, + isWsl, + shellIntegrationForActiveTerminal, + shouldUseProfileActivation, +} from './shells/common/shellUtils'; import { ShellEnvsProvider, ShellSetupState, ShellStartupScriptProvider } from './shells/startupProvider'; import { handleSettingUpShellProfile } from './shellStartupSetupHandlers'; import { @@ -166,20 +171,20 @@ export class TerminalManagerImpl implements TerminalManager { await Promise.all( providers.map(async (p) => { const state = await p.isSetup(); - const shellIntegrationEnabled = await getShellIntegrationEnabledCache(); + const shellIntegrationEnabledSetting = await getShellIntegrationEnabledCache(); + const shellIntegrationActiveTerminal = await shellIntegrationForActiveTerminal(p.name); + const shellIntegrationLikelyAvailable = + shellIntegrationEnabledSetting || shellIntegrationActiveTerminal; traceVerbose(`Checking shell profile for ${p.shellType}, with state: ${state}`); + if (state === ShellSetupState.NotSetup) { traceVerbose( - `WSL detected: ${isWsl()}, Shell integration available from setting, or active terminal: ${shellIntegrationEnabled}, or ${await shellIntegrationForActiveTerminal( + `WSL detected: ${isWsl()}, Shell integration available from setting, or active terminal: ${shellIntegrationEnabledSetting}, or ${await shellIntegrationForActiveTerminal( p.name, )}`, ); - if ( - (shellIntegrationEnabled || (await shellIntegrationForActiveTerminal(p.name))) && - !isWsl() && - p.shellType !== 'cmd' - ) { + if (shellIntegrationLikelyAvailable && !shouldUseProfileActivation(p.shellType)) { // Shell integration available and NOT in WSL - skip setup await p.teardownScripts(); this.shellSetup.set(p.shellType, true); @@ -195,11 +200,7 @@ export class TerminalManagerImpl implements TerminalManager { ); } } else if (state === ShellSetupState.Setup) { - if ( - (shellIntegrationEnabled || (await shellIntegrationForActiveTerminal(p.name))) && - !isWsl() && - p.shellType !== 'cmd' - ) { + if (shellIntegrationLikelyAvailable && !shouldUseProfileActivation(p.shellType)) { await p.teardownScripts(); traceVerbose( `Shell integration available for ${p.shellType}, removed profile script in favor of shell integration.`, From 5d44f620fdf4911b8eded714f94392dc44d13faf Mon Sep 17 00:00:00 2001 From: anthonykim1 Date: Tue, 2 Dec 2025 23:37:06 -0800 Subject: [PATCH 3/3] Make sure to switch to COMMAND when user declines profile modification --- src/features/terminal/shellStartupSetupHandlers.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/features/terminal/shellStartupSetupHandlers.ts b/src/features/terminal/shellStartupSetupHandlers.ts index b9da1e8d..0a818ee2 100644 --- a/src/features/terminal/shellStartupSetupHandlers.ts +++ b/src/features/terminal/shellStartupSetupHandlers.ts @@ -55,6 +55,10 @@ export async function handleSettingUpShellProfile( }); providers.forEach((provider) => callback(provider, false)); } + } else { + traceInfo(`User declined shell profile setup for ${shells}, switching to command activation`); + await Promise.all(providers.map((provider) => provider.teardownScripts())); + await setAutoActivationType(ACT_TYPE_COMMAND); } }