@@ -147,15 +147,23 @@ export class TerminalManagerImpl implements TerminalManager {
147147 const shellsToSetup : ShellStartupScriptProvider [ ] = [ ] ;
148148 await Promise . all (
149149 providers . map ( async ( p ) => {
150+ const state = await p . isSetup ( ) ;
150151 if ( this . shellSetup . has ( p . shellType ) ) {
151- traceVerbose ( `Shell profile for ${ p . shellType } already checked.` ) ;
152- return ;
152+ // This ensures modified scripts are detected even after initial setup
153+ const cachedSetup = this . shellSetup . get ( p . shellType ) ;
154+ if ( ( state === ShellSetupState . Setup ) !== cachedSetup ) {
155+ traceVerbose ( `Shell profile for ${ p . shellType } state changed, updating cache.` ) ;
156+ // State changed - clear cache and re-evaluate
157+ this . shellSetup . delete ( p . shellType ) ;
158+ } else {
159+ traceVerbose ( `Shell profile for ${ p . shellType } already checked.` ) ;
160+ return ;
161+ }
153162 }
154163 traceVerbose ( `Checking shell profile for ${ p . shellType } .` ) ;
155- const state = await p . isSetup ( ) ;
156164 if ( state === ShellSetupState . NotSetup ) {
157- // Check if shell integration is available before marking for setup
158165 if ( shellIntegrationForActiveTerminal ( p . name ) ) {
166+ await p . teardownScripts ( ) ;
159167 this . shellSetup . set ( p . shellType , true ) ;
160168 traceVerbose (
161169 `Shell integration available for ${ p . shellType } , skipping prompt, and profile modification.` ,
@@ -169,6 +177,12 @@ export class TerminalManagerImpl implements TerminalManager {
169177 ) ;
170178 }
171179 } else if ( state === ShellSetupState . Setup ) {
180+ if ( shellIntegrationForActiveTerminal ( p . name ) ) {
181+ await p . teardownScripts ( ) ;
182+ traceVerbose (
183+ `Shell integration available for ${ p . shellType } , removed profile script in favor of shell integration.` ,
184+ ) ;
185+ }
172186 this . shellSetup . set ( p . shellType , true ) ;
173187 traceVerbose ( `Shell profile for ${ p . shellType } is setup.` ) ;
174188 } else if ( state === ShellSetupState . NotInstalled ) {
@@ -228,6 +242,7 @@ export class TerminalManagerImpl implements TerminalManager {
228242 let actType = getAutoActivationType ( ) ;
229243 const shellType = identifyTerminalShell ( terminal ) ;
230244 if ( actType === ACT_TYPE_SHELL ) {
245+ await this . handleSetupCheck ( shellType ) ;
231246 actType = await this . getEffectiveActivationType ( shellType ) ;
232247 }
233248
0 commit comments