Skip to content

Commit f88c515

Browse files
committed
get aliases to work for pwsh
1 parent 3fb71ec commit f88c515

File tree

5 files changed

+29
-9
lines changed

5 files changed

+29
-9
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ export interface ISerializedCommand {
252252
commandStartLineContent: string | undefined;
253253
timestamp: number;
254254
markProperties: IMarkProperties | undefined;
255+
aliases: string[][] | undefined;
255256
}
256257
export interface IMarkProperties {
257258
hoverMessage?: string;

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,8 @@ export class CommandDetectionCapability implements ICommandDetectionCapability {
565565
exitCode: e.exitCode,
566566
commandStartLineContent: e.commandStartLineContent,
567567
timestamp: e.timestamp,
568-
markProperties: e.markProperties
568+
markProperties: e.markProperties,
569+
aliases: e.aliases
569570
};
570571
});
571572
if (this._currentCommand.commandStartMarker) {
@@ -579,7 +580,8 @@ export class CommandDetectionCapability implements ICommandDetectionCapability {
579580
exitCode: undefined,
580581
commandStartLineContent: undefined,
581582
timestamp: 0,
582-
markProperties: undefined
583+
markProperties: undefined,
584+
aliases: this._aliases
583585
});
584586
}
585587
return {
@@ -784,12 +786,14 @@ function countNewLines(regex: RegExp): number {
784786

785787
function parseAliases(aliasString: string, isWindows?: boolean): string[][] {
786788
const aliases: string[][] = [];
787-
const rows = aliasString.split('\n');
788789
let shellType;
790+
const rows = aliasString.split('\n');
789791
if (isWindows || aliasString.includes('Definition')) {
790792
shellType = 'pwsh';
791793
// Remove the column headers
792794
rows.shift();
795+
rows.shift();
796+
rows.shift();
793797
} else if (rows.length > 1 && rows[1].startsWith('alias')) {
794798
shellType = 'bash';
795799
} else {
@@ -802,7 +806,7 @@ function parseAliases(aliasString: string, isWindows?: boolean): string[][] {
802806
} else if (shellType === 'bash') {
803807
aliases.push(row.substring(6).split('='));
804808
} else {
805-
aliases.push(row.split(''));
809+
aliases.push(row.split('\s+'));
806810
}
807811
}
808812
console.log(aliases);

src/vs/workbench/api/browser/mainThreadTerminalService.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { Promises } from 'vs/base/common/async';
2525
import { CancellationToken } from 'vs/base/common/cancellation';
2626
import { ITerminalCommand } from 'vs/platform/terminal/common/capabilities/capabilities';
2727
import { ITerminalOutputMatch, ITerminalOutputMatcher, ITerminalQuickFixOptions } from 'vs/platform/terminal/common/xterm/terminalQuickFix';
28+
import { resolveAliases } from 'vs/workbench/contrib/terminal/browser/xterm/quickFixAddon';
2829

2930
@extHostNamedCustomer(MainContext.MainThreadTerminalService)
3031
export class MainThreadTerminalService implements MainThreadTerminalServiceShape {
@@ -259,8 +260,15 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
259260
option.outputMatcher.length = 40;
260261
this._logService.warn('Cannot exceed output matcher length of 40');
261262
}
262-
const commandLineMatch = terminalCommand.command.match(option.commandLineMatcher);
263+
let commandLineMatch = terminalCommand.command.match(option.commandLineMatcher);
263264
if (!commandLineMatch) {
265+
if (terminalCommand.aliases) {
266+
const resolvedCommand = resolveAliases(terminalCommand.command, terminalCommand.aliases);
267+
commandLineMatch = resolvedCommand.match(option.commandLineMatcher);
268+
if (!commandLineMatch) {
269+
return;
270+
}
271+
}
264272
return;
265273
}
266274
const outputMatcher = option.outputMatcher;

src/vs/workbench/contrib/terminal/browser/media/shellIntegration.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,7 @@ function Set-MappedKeyHandlers {
9292
Set-MappedKeyHandler -Chord Shift+End -Sequence 'F12,d'
9393
}
9494
Set-MappedKeyHandlers
95-
[Console]::Write("`e]633;P;UserAliases=$(Get-Alias | Select-Object Name, Definition)`a")
95+
$result = $(Get-Alias | Select-Object Name, Definition)
96+
$resultStr = Out-String -InputObject $result
97+
$resultStr = $resultStr.Replace("\", "\\").Replace("`n", "\x0a").Replace(";", "\x3b")
98+
[Console]::Write("`e]633;P;UserAliases=$resultStr`a")

src/vs/workbench/contrib/terminal/browser/xterm/quickFixAddon.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,13 @@ export async function getQuickFixesForCommand(
328328
}
329329
quickFixes = await getResolvedFixes(option, option.outputMatcher ? getLinesForCommand(terminal.buffer.active, terminalCommand, terminal.cols, option.outputMatcher) : undefined);
330330
} else if (option.type === 'internal') {
331-
const commandLineMatch = newCommand.match(option.commandLineMatcher);
331+
let commandLineMatch = newCommand.match(option.commandLineMatcher);
332332
if (!commandLineMatch) {
333-
continue;
333+
const resolvedAliasesCommand = resolveAliases(newCommand, terminalCommand.aliases);
334+
commandLineMatch = resolvedAliasesCommand.match(option.commandLineMatcher);
335+
if (!commandLineMatch) {
336+
continue;
337+
}
334338
}
335339
const outputMatcher = option.outputMatcher;
336340
let outputMatch;
@@ -427,7 +431,7 @@ function convertToQuickFixOptions(selectorProvider: ITerminalQuickFixProviderSel
427431
};
428432
}
429433

430-
function resolveAliases(commandLine: string, aliases?: string[][]): string {
434+
export function resolveAliases(commandLine: string, aliases?: string[][]): string {
431435
if (!aliases) {
432436
return commandLine;
433437
}

0 commit comments

Comments
 (0)