Skip to content

Commit 330ab6c

Browse files
Reland fix custom task shell doesn't work without manually passing in "run command" arg/flag (microsoft#236058)
1 parent b4c9953 commit 330ab6c

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

src/vs/platform/terminal/common/terminal.ts

+1
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,7 @@ export interface ITerminalProfile {
871871
overrideName?: boolean;
872872
color?: string;
873873
icon?: ThemeIcon | URI | { light: URI; dark: URI };
874+
isAutomationShell?: boolean;
874875
}
875876

876877
export interface ITerminalDimensionsOverride extends Readonly<ITerminalDimensions> {

src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts

+19-14
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,6 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
11121112
color: task.configurationProperties.icon?.color || undefined,
11131113
waitOnExit
11141114
};
1115-
let shellSpecified: boolean = false;
11161115
const shellOptions: IShellConfiguration | undefined = task.command.options && task.command.options.shell;
11171116
if (shellOptions) {
11181117
if (shellOptions.executable) {
@@ -1121,12 +1120,12 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
11211120
shellLaunchConfig.args = undefined;
11221121
}
11231122
shellLaunchConfig.executable = await this._resolveVariable(variableResolver, shellOptions.executable);
1124-
shellSpecified = true;
11251123
}
11261124
if (shellOptions.args) {
11271125
shellLaunchConfig.args = await this._resolveVariables(variableResolver, shellOptions.args.slice());
11281126
}
11291127
}
1128+
const taskShellArgsSpecified = (defaultProfile.isAutomationShell ? shellLaunchConfig.args : shellOptions?.args) !== undefined;
11301129
if (shellLaunchConfig.args === undefined) {
11311130
shellLaunchConfig.args = [];
11321131
}
@@ -1139,29 +1138,34 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
11391138
windowsShellArgs = true;
11401139
// If we don't have a cwd, then the terminal uses the home dir.
11411140
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) {
11471150
toAdd.push('-Command');
11481151
}
11491152
} else if ((basename === 'bash.exe') || (basename === 'zsh.exe')) {
11501153
windowsShellArgs = false;
1151-
if (!shellSpecified) {
1154+
if (!taskShellArgsSpecified) {
11521155
toAdd.push('-c');
11531156
}
11541157
} else if (basename === 'wsl.exe') {
1155-
if (!shellSpecified) {
1158+
if (!taskShellArgsSpecified) {
11561159
toAdd.push('-e');
11571160
}
11581161
} 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');
11611165
}
11621166
}
11631167
} else {
1164-
if (!shellSpecified) {
1168+
if (!taskShellArgsSpecified) {
11651169
// Under Mac remove -l to not start it as a login shell.
11661170
if (platform === Platform.Platform.Mac) {
11671171
// Background on -l on osx https://github.com/microsoft/vscode/issues/107563
@@ -1268,11 +1272,12 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
12681272
const combinedShellArgs: string[] = Objects.deepClone(configuredShellArgs);
12691273
shellCommandArgs.forEach(element => {
12701274
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)) {
12721277
// We can still add the argument, but only if not all of the following arguments begin with "-".
12731278
return !configuredShellArgs.slice(index + 1).every(testArg => testArg.startsWith('-'));
12741279
} else {
1275-
return arg.toLowerCase() !== element;
1280+
return !isDuplicated;
12761281
}
12771282
});
12781283
if (shouldAddShellCommandArg) {

src/vs/workbench/contrib/terminal/browser/terminalProfileResolverService.ts

+1
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ export abstract class BaseTerminalProfileResolverService extends Disposable impl
268268
const automationProfile = this._configurationService.getValue(`terminal.integrated.automationProfile.${this._getOsKey(options.os)}`);
269269
if (this._isValidAutomationProfile(automationProfile, options.os)) {
270270
automationProfile.icon = this._getCustomIcon(automationProfile.icon) || Codicon.tools;
271+
automationProfile.isAutomationShell = true;
271272
return automationProfile;
272273
}
273274

0 commit comments

Comments
 (0)