diff --git a/src/features/terminal/shells/bash/bashStartup.ts b/src/features/terminal/shells/bash/bashStartup.ts index 86838d5c..e62ad1af 100644 --- a/src/features/terminal/shells/bash/bashStartup.ts +++ b/src/features/terminal/shells/bash/bashStartup.ts @@ -61,14 +61,12 @@ function getActivationContent(key: string): string { async function isStartupSetup(profile: string, key: string): Promise { if (await fs.pathExists(profile)) { const content = await fs.readFile(profile, 'utf8'); - return hasStartupCode(content, regionStart, regionEnd, [key]) - ? ShellSetupState.Setup - : ShellSetupState.NotSetup; - } else { - return ShellSetupState.NotSetup; + if (hasStartupCode(content, regionStart, regionEnd, [key])) { + return ShellSetupState.Setup; + } } + return ShellSetupState.NotSetup; } - async function setupStartup(profile: string, key: string, name: string): Promise { if (shellIntegrationForActiveTerminal(name, profile)) { removeStartup(profile, key); diff --git a/src/features/terminal/terminalManager.ts b/src/features/terminal/terminalManager.ts index a985c079..dcba585c 100644 --- a/src/features/terminal/terminalManager.ts +++ b/src/features/terminal/terminalManager.ts @@ -147,15 +147,23 @@ export class TerminalManagerImpl implements TerminalManager { const shellsToSetup: ShellStartupScriptProvider[] = []; await Promise.all( providers.map(async (p) => { + const state = await p.isSetup(); if (this.shellSetup.has(p.shellType)) { - traceVerbose(`Shell profile for ${p.shellType} already checked.`); - return; + // This ensures modified scripts are detected even after initial setup + const cachedSetup = this.shellSetup.get(p.shellType); + if ((state === ShellSetupState.Setup) !== cachedSetup) { + traceVerbose(`Shell profile for ${p.shellType} state changed, updating cache.`); + // State changed - clear cache and re-evaluate + this.shellSetup.delete(p.shellType); + } else { + traceVerbose(`Shell profile for ${p.shellType} already checked.`); + return; + } } traceVerbose(`Checking shell profile for ${p.shellType}.`); - const state = await p.isSetup(); if (state === ShellSetupState.NotSetup) { - // Check if shell integration is available before marking for setup if (shellIntegrationForActiveTerminal(p.name)) { + await p.teardownScripts(); this.shellSetup.set(p.shellType, true); traceVerbose( `Shell integration available for ${p.shellType}, skipping prompt, and profile modification.`, @@ -169,6 +177,12 @@ export class TerminalManagerImpl implements TerminalManager { ); } } else if (state === ShellSetupState.Setup) { + if (shellIntegrationForActiveTerminal(p.name)) { + await p.teardownScripts(); + traceVerbose( + `Shell integration available for ${p.shellType}, removed profile script in favor of shell integration.`, + ); + } this.shellSetup.set(p.shellType, true); traceVerbose(`Shell profile for ${p.shellType} is setup.`); } else if (state === ShellSetupState.NotInstalled) { @@ -228,6 +242,7 @@ export class TerminalManagerImpl implements TerminalManager { let actType = getAutoActivationType(); const shellType = identifyTerminalShell(terminal); if (actType === ACT_TYPE_SHELL) { + await this.handleSetupCheck(shellType); actType = await this.getEffectiveActivationType(shellType); }