Skip to content

Commit 5a33232

Browse files
committed
add shellIntegrationSupportedShells, revert cmdStartup.ts
1 parent c72c03f commit 5a33232

File tree

3 files changed

+35
-21
lines changed

3 files changed

+35
-21
lines changed

src/features/terminal/shells/cmd/cmdStartup.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,12 @@ async function setupCmdStartup(cmdFiles: CmdFilePaths, key: string): Promise<boo
208208
const existingAutoRun = await getExistingAutoRun();
209209

210210
// Step 3: Create or update the main batch file
211-
const mainBatchContent = getMainBatchFileContent(cmdFiles.regStartupFile);
212211
if (await fs.pathExists(cmdFiles.mainBatchFile)) {
213212
const content = await fs.readFile(cmdFiles.mainBatchFile, 'utf8');
214213
if (hasStartupCode(content, regionStart, regionEnd, [cmdFiles.startupName])) {
215214
traceInfo(`SHELL: CMD main batch file at ${cmdFiles.mainBatchFile} already contains our startup file`);
216215
} else {
216+
const mainBatchContent = getMainBatchFileContent(cmdFiles.regStartupFile);
217217
await fs.writeFile(
218218
cmdFiles.mainBatchFile,
219219
insertStartupCode(content, regionStart, regionEnd, mainBatchContent),
@@ -222,13 +222,6 @@ async function setupCmdStartup(cmdFiles: CmdFilePaths, key: string): Promise<boo
222222
`SHELL: Updated existing main batch file at: ${cmdFiles.mainBatchFile}\r\n${mainBatchContent}`,
223223
);
224224
}
225-
} else {
226-
// Create new main batch file
227-
await fs.writeFile(
228-
cmdFiles.mainBatchFile,
229-
insertStartupCode(getHeader(), regionStart, regionEnd, mainBatchContent),
230-
);
231-
traceInfo(`SHELL: Created new main batch file at: ${cmdFiles.mainBatchFile}\r\n${mainBatchContent}`);
232225
}
233226

234227
// Step 4: Setup registry AutoRun to call our main batch file

src/features/terminal/shells/common/shellUtils.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,23 @@ export async function getShellIntegrationEnabledCache(): Promise<boolean> {
161161
await persistentState.set(SHELL_INTEGRATION_STATE_KEY, shellIntegrationEnabled);
162162
return shellIntegrationEnabled;
163163
}
164+
165+
// Shells that support shell integration way of environment activation.
166+
// CMD is not listed here, but we still want to support activation via profile modification.
167+
export const shellIntegrationSupportedShells = [
168+
ShellConstants.PWSH,
169+
ShellConstants.BASH,
170+
ShellConstants.GITBASH,
171+
ShellConstants.FISH,
172+
ShellConstants.ZSH,
173+
];
174+
175+
/**
176+
* Determines whether profile-based activation should be used instead of shell integration.
177+
* Profile activation is preferred when:
178+
* - Running in WSL
179+
* - The shell type doesn't support shell integration (e.g., cmd)
180+
*/
181+
export function shouldUseProfileActivation(shellType: string): boolean {
182+
return isWsl() || !shellIntegrationSupportedShells.includes(shellType);
183+
}

src/features/terminal/terminalManager.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ import { getConfiguration, onDidChangeConfiguration } from '../../common/workspa
1616
import { isActivatableEnvironment } from '../common/activation';
1717
import { identifyTerminalShell } from '../common/shellDetector';
1818
import { getPythonApi } from '../pythonApi';
19-
import { getShellIntegrationEnabledCache, isWsl, shellIntegrationForActiveTerminal } from './shells/common/shellUtils';
19+
import {
20+
getShellIntegrationEnabledCache,
21+
isWsl,
22+
shellIntegrationForActiveTerminal,
23+
shouldUseProfileActivation,
24+
} from './shells/common/shellUtils';
2025
import { ShellEnvsProvider, ShellSetupState, ShellStartupScriptProvider } from './shells/startupProvider';
2126
import { handleSettingUpShellProfile } from './shellStartupSetupHandlers';
2227
import {
@@ -166,20 +171,20 @@ export class TerminalManagerImpl implements TerminalManager {
166171
await Promise.all(
167172
providers.map(async (p) => {
168173
const state = await p.isSetup();
169-
const shellIntegrationEnabled = await getShellIntegrationEnabledCache();
174+
const shellIntegrationEnabledSetting = await getShellIntegrationEnabledCache();
175+
const shellIntegrationActiveTerminal = await shellIntegrationForActiveTerminal(p.name);
176+
const shellIntegrationLikelyAvailable =
177+
shellIntegrationEnabledSetting || shellIntegrationActiveTerminal;
170178
traceVerbose(`Checking shell profile for ${p.shellType}, with state: ${state}`);
179+
171180
if (state === ShellSetupState.NotSetup) {
172181
traceVerbose(
173-
`WSL detected: ${isWsl()}, Shell integration available from setting, or active terminal: ${shellIntegrationEnabled}, or ${await shellIntegrationForActiveTerminal(
182+
`WSL detected: ${isWsl()}, Shell integration available from setting, or active terminal: ${shellIntegrationEnabledSetting}, or ${await shellIntegrationForActiveTerminal(
174183
p.name,
175184
)}`,
176185
);
177186

178-
if (
179-
(shellIntegrationEnabled || (await shellIntegrationForActiveTerminal(p.name))) &&
180-
!isWsl() &&
181-
p.shellType !== 'cmd'
182-
) {
187+
if (shellIntegrationLikelyAvailable && !shouldUseProfileActivation(p.shellType)) {
183188
// Shell integration available and NOT in WSL - skip setup
184189
await p.teardownScripts();
185190
this.shellSetup.set(p.shellType, true);
@@ -195,11 +200,7 @@ export class TerminalManagerImpl implements TerminalManager {
195200
);
196201
}
197202
} else if (state === ShellSetupState.Setup) {
198-
if (
199-
(shellIntegrationEnabled || (await shellIntegrationForActiveTerminal(p.name))) &&
200-
!isWsl() &&
201-
p.shellType !== 'cmd'
202-
) {
203+
if (shellIntegrationLikelyAvailable && !shouldUseProfileActivation(p.shellType)) {
203204
await p.teardownScripts();
204205
traceVerbose(
205206
`Shell integration available for ${p.shellType}, removed profile script in favor of shell integration.`,

0 commit comments

Comments
 (0)