Reland fix custom task shell doesn't work without manually passing in "run command" arg/flag (#236058)

pull/235880/head^2
Tony 2024-12-18 01:50:35 +08:00 committed by GitHub
parent b4c9953da4
commit 330ab6c292
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 14 deletions

View File

@ -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> {

View File

@ -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) {
@ -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 = [];
}
@ -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
@ -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) {

View File

@ -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;
}