@@ -1112,6 +1112,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
1112
1112
color : task . configurationProperties . icon ?. color || undefined ,
1113
1113
waitOnExit
1114
1114
} ;
1115
+ let shellSpecified : boolean = false ;
1115
1116
const shellOptions : IShellConfiguration | undefined = task . command . options && task . command . options . shell ;
1116
1117
if ( shellOptions ) {
1117
1118
if ( shellOptions . executable ) {
@@ -1120,12 +1121,12 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
1120
1121
shellLaunchConfig . args = undefined ;
1121
1122
}
1122
1123
shellLaunchConfig . executable = await this . _resolveVariable ( variableResolver , shellOptions . executable ) ;
1124
+ shellSpecified = true ;
1123
1125
}
1124
1126
if ( shellOptions . args ) {
1125
1127
shellLaunchConfig . args = await this . _resolveVariables ( variableResolver , shellOptions . args . slice ( ) ) ;
1126
1128
}
1127
1129
}
1128
- const taskShellArgsSpecified = ( defaultProfile . isAutomationShell ? shellLaunchConfig . args : shellOptions ?. args ) !== undefined ;
1129
1130
if ( shellLaunchConfig . args === undefined ) {
1130
1131
shellLaunchConfig . args = [ ] ;
1131
1132
}
@@ -1138,34 +1139,29 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
1138
1139
windowsShellArgs = true ;
1139
1140
// If we don't have a cwd, then the terminal uses the home dir.
1140
1141
const userHome = await this . _pathService . userHome ( ) ;
1141
- if ( basename === 'cmd.exe' ) {
1142
- if ( ( options . cwd && isUNC ( options . cwd ) ) || ( ! options . cwd && isUNC ( userHome . fsPath ) ) ) {
1143
- return undefined ;
1144
- }
1145
- if ( ! taskShellArgsSpecified ) {
1146
- toAdd . push ( '/d' , '/c' ) ;
1147
- }
1148
- } else if ( ( basename === 'powershell.exe' ) || ( basename === 'pwsh.exe' ) ) {
1149
- if ( ! taskShellArgsSpecified ) {
1142
+ if ( basename === 'cmd.exe' && ( ( options . cwd && isUNC ( options . cwd ) ) || ( ! options . cwd && isUNC ( userHome . fsPath ) ) ) ) {
1143
+ return undefined ;
1144
+ }
1145
+ if ( ( basename === 'powershell.exe' ) || ( basename === 'pwsh.exe' ) ) {
1146
+ if ( ! shellSpecified ) {
1150
1147
toAdd . push ( '-Command' ) ;
1151
1148
}
1152
1149
} else if ( ( basename === 'bash.exe' ) || ( basename === 'zsh.exe' ) ) {
1153
1150
windowsShellArgs = false ;
1154
- if ( ! taskShellArgsSpecified ) {
1151
+ if ( ! shellSpecified ) {
1155
1152
toAdd . push ( '-c' ) ;
1156
1153
}
1157
1154
} else if ( basename === 'wsl.exe' ) {
1158
- if ( ! taskShellArgsSpecified ) {
1155
+ if ( ! shellSpecified ) {
1159
1156
toAdd . push ( '-e' ) ;
1160
1157
}
1161
1158
} else {
1162
- if ( ! taskShellArgsSpecified ) {
1163
- // Push `-c` for unknown shells if the user didn't specify the args
1164
- toAdd . push ( '-c' ) ;
1159
+ if ( ! shellSpecified ) {
1160
+ toAdd . push ( '/d' , '/c' ) ;
1165
1161
}
1166
1162
}
1167
1163
} else {
1168
- if ( ! taskShellArgsSpecified ) {
1164
+ if ( ! shellSpecified ) {
1169
1165
// Under Mac remove -l to not start it as a login shell.
1170
1166
if ( platform === Platform . Platform . Mac ) {
1171
1167
// Background on -l on osx https://github.com/microsoft/vscode/issues/107563
@@ -1272,12 +1268,11 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
1272
1268
const combinedShellArgs : string [ ] = Objects . deepClone ( configuredShellArgs ) ;
1273
1269
shellCommandArgs . forEach ( element => {
1274
1270
const shouldAddShellCommandArg = configuredShellArgs . every ( ( arg , index ) => {
1275
- const isDuplicated = arg . toLowerCase ( ) === element . toLowerCase ( ) ;
1276
- if ( isDuplicated && ( configuredShellArgs . length > index + 1 ) ) {
1271
+ if ( ( arg . toLowerCase ( ) === element ) && ( configuredShellArgs . length > index + 1 ) ) {
1277
1272
// We can still add the argument, but only if not all of the following arguments begin with "-".
1278
1273
return ! configuredShellArgs . slice ( index + 1 ) . every ( testArg => testArg . startsWith ( '-' ) ) ;
1279
1274
} else {
1280
- return ! isDuplicated ;
1275
+ return arg . toLowerCase ( ) !== element ;
1281
1276
}
1282
1277
} ) ;
1283
1278
if ( shouldAddShellCommandArg ) {
0 commit comments