@@ -22,12 +22,18 @@ const commandExists = (path: string): Promise<boolean> => ensureCommandExists(pa
22
22
const DEFAULT_GIT_BASH_PATH = 'C:/Program Files/git/git-bash.exe' ;
23
23
const PATH_VAR_SEPARATOR = process . platform === 'win32' ? ';' : ':' ;
24
24
const SHELL = ( process . env . SHELL || '' ) . split ( '/' ) . slice ( - 1 ) [ 0 ] ;
25
+
25
26
const OVERRIDE_BIN_PATH = path . join ( __dirname , 'terminal-wrappers' ) ;
27
+ // Generate POSIX paths for git-bash on Windows (or use the normal path everywhere where)
28
+ const POSIX_OVERRIDE_BIN_PATH = process . platform === 'win32'
29
+ ? OVERRIDE_BIN_PATH . replace ( / \\ / g, '/' ) . replace ( / ^ ( \w + ) : / , ( _all , driveLetter ) => `/${ driveLetter . toLowerCase ( ) } ` )
30
+ : OVERRIDE_BIN_PATH ;
26
31
27
32
interface SpawnArgs {
28
33
command : string ;
29
34
args ?: string [ ] ;
30
35
options ?: SpawnOptions ;
36
+ skipStartupScripts ?: true ;
31
37
}
32
38
33
39
const getTerminalCommand = _ . memoize ( async ( ) : Promise < SpawnArgs | null > => {
@@ -37,7 +43,7 @@ const getTerminalCommand = _.memoize(async (): Promise<SpawnArgs | null> => {
37
43
} else if ( await canAccess ( DEFAULT_GIT_BASH_PATH ) ) {
38
44
return { command : DEFAULT_GIT_BASH_PATH } ;
39
45
} else {
40
- return { command : 'start' , args : [ 'cmd' ] , options : { shell : true } } ;
46
+ return { command : 'start' , args : [ 'cmd' ] , options : { shell : true } , skipStartupScripts : true } ;
41
47
}
42
48
} else if ( process . platform === 'linux' ) {
43
49
if ( GSettings . isAvailable ( ) ) {
@@ -200,13 +206,13 @@ export class TerminalInterceptor implements Interceptor {
200
206
const terminalSpawnArgs = await getTerminalCommand ( ) ;
201
207
if ( ! terminalSpawnArgs ) throw new Error ( 'Could not find a suitable terminal' ) ;
202
208
203
- const { command, args, options } = terminalSpawnArgs ;
209
+ const { command, args, options, skipStartupScripts } = terminalSpawnArgs ;
204
210
205
- // On OSX, our PATH override below doesn't work, because path_helper always runs and prepends
206
- // the real paths over the top. To fix this, we (very carefully!) rewrite shell startup
207
- // scripts, to reset PATH there .
211
+ // Our PATH override below may not work, e.g. because OSX's path_helper always prepends
212
+ // the real paths over the top, and git-bash ignore env var paths overrides. To fix this,
213
+ // we (very carefully!) rewrite shell startup scripts, to reset the PATH in our shell .
208
214
// This gets reset on exit, and is behind a flag so it won't affect other shells anyway.
209
- if ( process . platform === 'darwin' ) await editShellStartupScripts ( ) ;
215
+ if ( ! skipStartupScripts ) await editShellStartupScripts ( ) ;
210
216
211
217
const childProc = spawn (
212
218
command ,
@@ -242,8 +248,13 @@ export class TerminalInterceptor implements Interceptor {
242
248
terminals [ proxyPort ] = ( terminals [ proxyPort ] || [ ] ) . concat ( childProc ) ;
243
249
244
250
const onTerminalClosed = ( ) => {
245
- if ( process . platform === 'darwin' ) resetShellStartupScripts ( ) ;
246
251
terminals [ proxyPort ] = _ . reject ( terminals [ proxyPort ] , childProc ) ;
252
+
253
+ // Delay slightly as some terminals (gnome-terminal) exit immediately,
254
+ // and start the terminal elsewhere, so it may not have started yet.
255
+ setTimeout ( ( ) => {
256
+ if ( _ . every ( terminals , ts => _ . isEmpty ( ts ) ) ) resetShellStartupScripts ( ) ;
257
+ } , 500 ) ;
247
258
} ;
248
259
childProc . once ( 'exit' , onTerminalClosed ) ;
249
260
childProc . once ( 'error' , ( e ) => {
0 commit comments