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