@@ -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