@@ -499,8 +499,11 @@ export function isBaseCondaEnv(envPath: string): boolean {
499
499
export function createCommandScriptInEnv (
500
500
envPath : string ,
501
501
baseCondaEnvPath : string ,
502
- command ?: string ,
503
- joinStr ?: string
502
+ options ?: {
503
+ command ?: string ;
504
+ quoteChar ?: string ;
505
+ joinStr ?: string ;
506
+ }
504
507
) : string {
505
508
try {
506
509
const stat = fs . lstatSync ( envPath ) ;
@@ -511,9 +514,9 @@ export function createCommandScriptInEnv(
511
514
//
512
515
}
513
516
514
- if ( joinStr === undefined ) {
515
- joinStr = '\n' ;
516
- }
517
+ const quoteChar = options ?. quoteChar || '"' ;
518
+ const joinStr = options ?. joinStr || '\n' ;
519
+ let command = options ?. command ;
517
520
const isWin = process . platform === 'win32' ;
518
521
519
522
let activatePath = activatePathForEnvPath ( envPath ) ;
@@ -555,11 +558,11 @@ export function createCommandScriptInEnv(
555
558
scriptLines . push ( `CALL ${ command } ` ) ;
556
559
}
557
560
} else {
558
- scriptLines . push ( `source " ${ activatePath } " ` ) ;
561
+ scriptLines . push ( `source ${ quoteChar } ${ activatePath } ${ quoteChar } ` ) ;
559
562
if ( isConda && isBaseCondaActivate ) {
560
- scriptLines . push ( `source " ${ condaSourcePath } " ` ) ;
563
+ scriptLines . push ( `source ${ quoteChar } ${ condaSourcePath } ${ quoteChar } ` ) ;
561
564
if ( ! isCondaCommand ) {
562
- scriptLines . push ( `conda activate " ${ envPath } " ` ) ;
565
+ scriptLines . push ( `conda activate ${ quoteChar } ${ envPath } ${ quoteChar } ` ) ;
563
566
}
564
567
}
565
568
if ( command ) {
@@ -668,15 +671,19 @@ export function openDirectoryInExplorer(dirPath: string): boolean {
668
671
return true ;
669
672
}
670
673
671
- export function launchTerminalInDirectory (
672
- dirPath : string ,
673
- commands ?: string
674
- ) : boolean {
674
+ export function launchTerminalInDirectory ( options : {
675
+ dirPath : string ;
676
+ interactive : boolean ;
677
+ commands ?: string ;
678
+ } ) : boolean {
679
+ const { dirPath, interactive } = options ;
675
680
if ( ! ( fs . existsSync ( dirPath ) && fs . statSync ( dirPath ) . isDirectory ( ) ) ) {
676
681
return false ;
677
682
}
678
683
679
684
const { platform } = process ;
685
+ let commands = options . commands ;
686
+
680
687
if ( platform === 'darwin' ) {
681
688
let callCommands = '' ;
682
689
if ( commands ) {
@@ -711,7 +718,11 @@ export function launchTerminalInDirectory(
711
718
} else {
712
719
let callCommands = '' ;
713
720
if ( commands ) {
714
- callCommands = ` -- bash -c "${ commands } ; exec bash"` ;
721
+ // note that calling "exec bash" at the end will cause .bashrc to be reloaded,
722
+ // which could possibly override python path (e.g. base conda initialization)
723
+ callCommands = ` -- bash -c "${ commands } ${
724
+ interactive ? '; exec bash' : ''
725
+ } "`;
715
726
}
716
727
exec ( `gnome-terminal --working-directory="${ dirPath } "${ callCommands } ` ) ;
717
728
}
0 commit comments