Skip to content

Commit

Permalink
Fix custom task shell doesn't work without manually passing in "run c…
Browse files Browse the repository at this point in the history
…ommand" arg/flag (#181760)
  • Loading branch information
Legend-Master authored Dec 12, 2024
1 parent d590c74 commit fc3cc5b
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,6 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
color: task.configurationProperties.icon?.color || undefined,
waitOnExit
};
let shellSpecified: boolean = false;
const shellOptions: IShellConfiguration | undefined = task.command.options && task.command.options.shell;
if (shellOptions) {
if (shellOptions.executable) {
Expand All @@ -1120,12 +1119,12 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
shellLaunchConfig.args = undefined;
}
shellLaunchConfig.executable = await this._resolveVariable(variableResolver, shellOptions.executable);
shellSpecified = true;
}
if (shellOptions.args) {
shellLaunchConfig.args = await this._resolveVariables(variableResolver, shellOptions.args.slice());
}
}
const shellArgsSpecified: boolean = shellLaunchConfig.args !== undefined;
if (shellLaunchConfig.args === undefined) {
shellLaunchConfig.args = [];
}
Expand All @@ -1138,29 +1137,29 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
windowsShellArgs = true;
// If we don't have a cwd, then the terminal uses the home dir.
const userHome = await this._pathService.userHome();
if (basename === 'cmd.exe' && ((options.cwd && isUNC(options.cwd)) || (!options.cwd && isUNC(userHome.fsPath)))) {
return undefined;
}
if ((basename === 'powershell.exe') || (basename === 'pwsh.exe')) {
if (!shellSpecified) {
if (basename === 'cmd.exe') {
if ((options.cwd && isUNC(options.cwd)) || (!options.cwd && isUNC(userHome.fsPath))) {
return undefined;
}
if (!shellArgsSpecified) {
toAdd.push('/d', '/c');
}
} else if ((basename === 'powershell.exe') || (basename === 'pwsh.exe')) {
if (!shellArgsSpecified) {
toAdd.push('-Command');
}
} else if ((basename === 'bash.exe') || (basename === 'zsh.exe')) {
windowsShellArgs = false;
if (!shellSpecified) {
if (!shellArgsSpecified) {
toAdd.push('-c');
}
} else if (basename === 'wsl.exe') {
if (!shellSpecified) {
if (!shellArgsSpecified) {
toAdd.push('-e');
}
} else {
if (!shellSpecified) {
toAdd.push('/d', '/c');
}
}
} else {
if (!shellSpecified) {
if (!shellArgsSpecified) {
// Under Mac remove -l to not start it as a login shell.
if (platform === Platform.Platform.Mac) {
// Background on -l on osx https://github.com/microsoft/vscode/issues/107563
Expand Down Expand Up @@ -1267,11 +1266,12 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
const combinedShellArgs: string[] = Objects.deepClone(configuredShellArgs);
shellCommandArgs.forEach(element => {
const shouldAddShellCommandArg = configuredShellArgs.every((arg, index) => {
if ((arg.toLowerCase() === element) && (configuredShellArgs.length > index + 1)) {
const isDuplicated = arg.toLowerCase() === element.toLowerCase();
if (isDuplicated && (configuredShellArgs.length > index + 1)) {
// We can still add the argument, but only if not all of the following arguments begin with "-".
return !configuredShellArgs.slice(index + 1).every(testArg => testArg.startsWith('-'));
} else {
return arg.toLowerCase() !== element;
return !isDuplicated;
}
});
if (shouldAddShellCommandArg) {
Expand Down

0 comments on commit fc3cc5b

Please sign in to comment.