Skip to content

Commit

Permalink
Reland fix custom task shell doesn't work without manually passing in…
Browse files Browse the repository at this point in the history
… "run command" arg/flag (microsoft#236058)
  • Loading branch information
Legend-Master authored Dec 17, 2024
1 parent b4c9953 commit 330ab6c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/vs/platform/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,7 @@ export interface ITerminalProfile {
overrideName?: boolean;
color?: string;
icon?: ThemeIcon | URI | { light: URI; dark: URI };
isAutomationShell?: boolean;
}

export interface ITerminalDimensionsOverride extends Readonly<ITerminalDimensions> {
Expand Down
33 changes: 19 additions & 14 deletions src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,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 @@ -1121,12 +1120,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 taskShellArgsSpecified = (defaultProfile.isAutomationShell ? shellLaunchConfig.args : shellOptions?.args) !== undefined;
if (shellLaunchConfig.args === undefined) {
shellLaunchConfig.args = [];
}
Expand All @@ -1139,29 +1138,34 @@ 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 (!taskShellArgsSpecified) {
toAdd.push('/d', '/c');
}
} else if ((basename === 'powershell.exe') || (basename === 'pwsh.exe')) {
if (!taskShellArgsSpecified) {
toAdd.push('-Command');
}
} else if ((basename === 'bash.exe') || (basename === 'zsh.exe')) {
windowsShellArgs = false;
if (!shellSpecified) {
if (!taskShellArgsSpecified) {
toAdd.push('-c');
}
} else if (basename === 'wsl.exe') {
if (!shellSpecified) {
if (!taskShellArgsSpecified) {
toAdd.push('-e');
}
} else {
if (!shellSpecified) {
toAdd.push('/d', '/c');
if (!taskShellArgsSpecified) {
// Push `-c` for unknown shells if the user didn't specify the args
toAdd.push('-c');
}
}
} else {
if (!shellSpecified) {
if (!taskShellArgsSpecified) {
// 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 @@ -1268,11 +1272,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
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ export abstract class BaseTerminalProfileResolverService extends Disposable impl
const automationProfile = this._configurationService.getValue(`terminal.integrated.automationProfile.${this._getOsKey(options.os)}`);
if (this._isValidAutomationProfile(automationProfile, options.os)) {
automationProfile.icon = this._getCustomIcon(automationProfile.icon) || Codicon.tools;
automationProfile.isAutomationShell = true;
return automationProfile;
}

Expand Down

0 comments on commit 330ab6c

Please sign in to comment.