@@ -10,50 +10,36 @@ import { quoteArgs } from '../../../execution/execUtils';
1010 * - Zsh: When setopt HIST_IGNORE_SPACE is enabled
1111 * - Git Bash: Uses bash under the hood, same behavior as Bash
1212 */
13- export const shellsWithLeadingSpaceHistorySupport = [ ShellConstants . BASH , ShellConstants . ZSH , ShellConstants . GITBASH ] ;
13+ export const shellsWithLeadingSpaceHistorySupport = new Set ( [
14+ ShellConstants . BASH ,
15+ ShellConstants . ZSH ,
16+ ShellConstants . GITBASH ,
17+ ] ) ;
1418
15- function getCommandAsString ( command : PythonCommandRunConfiguration [ ] , shell : string , delimiter : string ) : string {
19+ const defaultShellDelimiter = '&&' ;
20+ const shellDelimiterByShell = new Map < string , string > ( [
21+ [ ShellConstants . PWSH , ';' ] ,
22+ [ ShellConstants . NU , ';' ] ,
23+ [ ShellConstants . FISH , '; and' ] ,
24+ ] ) ;
25+
26+ export function getShellCommandAsString ( shell : string , command : PythonCommandRunConfiguration [ ] ) : string {
27+ const delimiter = shellDelimiterByShell . get ( shell ) ?? defaultShellDelimiter ;
1628 const parts = [ ] ;
1729 for ( const cmd of command ) {
1830 const args = cmd . args ?? [ ] ;
1931 parts . push ( quoteArgs ( [ normalizeShellPath ( cmd . executable , shell ) , ...args ] ) . join ( ' ' ) ) ;
2032 }
21- if ( shell === ShellConstants . PWSH ) {
22- if ( parts . length === 1 ) {
23- return parts [ 0 ] ;
24- }
25- return parts . map ( ( p ) => `(${ p } )` ) . join ( ` ${ delimiter } ` ) ;
26- }
27- return parts . join ( ` ${ delimiter } ` ) ;
28- }
2933
30- export function getShellCommandAsString ( shell : string , command : PythonCommandRunConfiguration [ ] ) : string {
31- let commandStr : string ;
32- switch ( shell ) {
33- case ShellConstants . PWSH :
34- commandStr = getCommandAsString ( command , shell , ';' ) ;
35- break ;
36- case ShellConstants . NU :
37- commandStr = getCommandAsString ( command , shell , ';' ) ;
38- break ;
39- case ShellConstants . FISH :
40- commandStr = getCommandAsString ( command , shell , '; and' ) ;
41- break ;
42- case ShellConstants . BASH :
43- case ShellConstants . SH :
44- case ShellConstants . ZSH :
45-
46- case ShellConstants . CMD :
47- case ShellConstants . GITBASH :
48- default :
49- commandStr = getCommandAsString ( command , shell , '&&' ) ;
50- break ;
34+ let commandStr = parts . join ( ` ${ delimiter } ` ) ;
35+ if ( shell === ShellConstants . PWSH && parts . length > 1 ) {
36+ commandStr = parts . map ( ( p ) => `(${ p } )` ) . join ( ` ${ delimiter } ` ) ;
5137 }
5238
5339 // Add a leading space for shells that support history ignore with leading space.
5440 // This prevents the activation command from being saved in bash/zsh history
5541 // when HISTCONTROL=ignorespace (bash) or setopt HIST_IGNORE_SPACE (zsh) is set.
56- if ( shellsWithLeadingSpaceHistorySupport . includes ( shell ) ) {
42+ if ( shellsWithLeadingSpaceHistorySupport . has ( shell ) ) {
5743 return ` ${ commandStr } ` ;
5844 }
5945 return commandStr ;
0 commit comments