Skip to content

Commit 9277ec8

Browse files
committed
Fix where activation goes missing after user modifying rc scripts
1 parent 10e9cdf commit 9277ec8

2 files changed

Lines changed: 24 additions & 9 deletions

File tree

src/features/terminal/shells/bash/bashStartup.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,12 @@ function getActivationContent(key: string): string {
6161
async function isStartupSetup(profile: string, key: string): Promise<ShellSetupState> {
6262
if (await fs.pathExists(profile)) {
6363
const content = await fs.readFile(profile, 'utf8');
64-
return hasStartupCode(content, regionStart, regionEnd, [key])
65-
? ShellSetupState.Setup
66-
: ShellSetupState.NotSetup;
67-
} else {
68-
return ShellSetupState.NotSetup;
64+
if (hasStartupCode(content, regionStart, regionEnd, [key])) {
65+
return ShellSetupState.Setup;
66+
}
6967
}
68+
return ShellSetupState.NotSetup;
7069
}
71-
7270
async function setupStartup(profile: string, key: string, name: string): Promise<boolean> {
7371
if (shellIntegrationForActiveTerminal(name, profile)) {
7472
removeStartup(profile, key);

src/features/terminal/terminalManager.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,24 @@ export class TerminalManagerImpl implements TerminalManager {
148148
await Promise.all(
149149
providers.map(async (p) => {
150150
if (this.shellSetup.has(p.shellType)) {
151-
traceVerbose(`Shell profile for ${p.shellType} already checked.`);
152-
return;
151+
// This ensures modified scripts are detected even after initial setup
152+
const currentState = await p.isSetup();
153+
const cachedSetup = this.shellSetup.get(p.shellType);
154+
155+
if ((currentState === ShellSetupState.Setup) !== cachedSetup) {
156+
traceVerbose(`Shell profile for ${p.shellType} state changed, updating cache.`);
157+
// State changed - clear cache and re-evaluate
158+
this.shellSetup.delete(p.shellType);
159+
} else {
160+
traceVerbose(`Shell profile for ${p.shellType} already checked.`);
161+
return;
162+
}
153163
}
154164
traceVerbose(`Checking shell profile for ${p.shellType}.`);
155165
const state = await p.isSetup();
156166
if (state === ShellSetupState.NotSetup) {
157-
// Check if shell integration is available before marking for setup
158167
if (shellIntegrationForActiveTerminal(p.name)) {
168+
await p.teardownScripts();
159169
this.shellSetup.set(p.shellType, true);
160170
traceVerbose(
161171
`Shell integration available for ${p.shellType}, skipping prompt, and profile modification.`,
@@ -169,6 +179,12 @@ export class TerminalManagerImpl implements TerminalManager {
169179
);
170180
}
171181
} else if (state === ShellSetupState.Setup) {
182+
if (shellIntegrationForActiveTerminal(p.name)) {
183+
await p.teardownScripts();
184+
traceVerbose(
185+
`Shell integration available for ${p.shellType}, removed profile script in favor of shell integration.`,
186+
);
187+
}
172188
this.shellSetup.set(p.shellType, true);
173189
traceVerbose(`Shell profile for ${p.shellType} is setup.`);
174190
} else if (state === ShellSetupState.NotInstalled) {
@@ -228,6 +244,7 @@ export class TerminalManagerImpl implements TerminalManager {
228244
let actType = getAutoActivationType();
229245
const shellType = identifyTerminalShell(terminal);
230246
if (actType === ACT_TYPE_SHELL) {
247+
await this.handleSetupCheck(shellType);
231248
actType = await this.getEffectiveActivationType(shellType);
232249
}
233250

0 commit comments

Comments
 (0)