@@ -7,7 +7,7 @@ import { ShellConstants } from '../../../common/shellConstants';
77import { hasStartupCode , insertStartupCode , removeStartupCode } from '../common/editUtils' ;
88import { shellIntegrationForActiveTerminal } from '../common/shellUtils' ;
99import { ShellScriptEditState , ShellSetupState , ShellStartupScriptProvider } from '../startupProvider' ;
10- import { BASH_ENV_KEY , BASH_SCRIPT_VERSION , ZSH_ENV_KEY } from './bashConstants' ;
10+ import { BASH_ENV_KEY , BASH_OLD_ENV_KEY , BASH_SCRIPT_VERSION , ZSH_ENV_KEY , ZSH_OLD_ENV_KEY } from './bashConstants' ;
1111
1212async function isBashLikeInstalled ( ) : Promise < boolean > {
1313 const result = await Promise . all ( [ which ( 'bash' , { nothrow : true } ) , which ( 'sh' , { nothrow : true } ) ] ) ;
@@ -106,13 +106,13 @@ async function removeStartup(profile: string, key: string): Promise<boolean> {
106106 const content = await fs . readFile ( profile , 'utf8' ) ;
107107 if ( hasStartupCode ( content , regionStart , regionEnd , [ key ] ) ) {
108108 await fs . writeFile ( profile , removeStartupCode ( content , regionStart , regionEnd ) ) ;
109- traceInfo ( `SHELL: Removed activation from profile at: ${ profile } ` ) ;
109+ traceInfo ( `SHELL: Removed activation from profile at: ${ profile } , for key: ${ key } ` ) ;
110110 } else {
111- traceVerbose ( `Profile at ${ profile } does not contain activation code` ) ;
111+ traceVerbose ( `Profile at ${ profile } does not contain activation code, for key: ${ key } ` ) ;
112112 }
113113 return true ;
114114 } catch ( err ) {
115- traceVerbose ( `Failed to remove ${ profile } startup` , err ) ;
115+ traceVerbose ( `Failed to remove ${ profile } startup, for key: ${ key } ` , err ) ;
116116 return false ;
117117 }
118118}
@@ -171,6 +171,8 @@ export class BashStartupProvider implements ShellStartupScriptProvider {
171171
172172 try {
173173 const bashProfile = await getBashProfiles ( ) ;
174+ // Remove old environment variable if it exists
175+ await removeStartup ( bashProfile , BASH_OLD_ENV_KEY ) ;
174176 const result = await removeStartup ( bashProfile , BASH_ENV_KEY ) ;
175177 return result ? ShellScriptEditState . Edited : ShellScriptEditState . NotEdited ;
176178 } catch ( err ) {
@@ -233,6 +235,7 @@ export class ZshStartupProvider implements ShellStartupScriptProvider {
233235 }
234236 try {
235237 const zshProfiles = await getZshProfiles ( ) ;
238+ await removeStartup ( zshProfiles , ZSH_OLD_ENV_KEY ) ;
236239 const result = await removeStartup ( zshProfiles , ZSH_ENV_KEY ) ;
237240 return result ? ShellScriptEditState . Edited : ShellScriptEditState . NotEdited ;
238241 } catch ( err ) {
@@ -293,6 +296,7 @@ export class GitBashStartupProvider implements ShellStartupScriptProvider {
293296
294297 try {
295298 const bashProfiles = await getBashProfiles ( ) ;
299+ await removeStartup ( bashProfiles , BASH_OLD_ENV_KEY ) ;
296300 const result = await removeStartup ( bashProfiles , BASH_ENV_KEY ) ;
297301 return result ? ShellScriptEditState . Edited : ShellScriptEditState . NotEdited ;
298302 } catch ( err ) {
0 commit comments