Skip to content

Commit 3fb71ec

Browse files
committed
echo e is removing new lines
1 parent a35e6d9 commit 3fb71ec

File tree

7 files changed

+41
-18
lines changed

7 files changed

+41
-18
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ export interface ICommandDetectionCapability {
159159
readonly onCurrentCommandInvalidated: Event<ICommandInvalidationRequest>;
160160
setCwd(value: string): void;
161161
setIsWindowsPty(value: boolean): void;
162+
setAliases(value: string): void;
162163
setIsCommandStorageDisabled(): void;
163164
/**
164165
* Gets the working directory for a line, this will return undefined if it's unknown in which
@@ -221,6 +222,7 @@ export interface ITerminalCommand {
221222
executedMarker?: IXtermMarker;
222223
commandStartLineContent?: string;
223224
markProperties?: IMarkProperties;
225+
aliases?: string[][];
224226
getOutput(): string | undefined;
225227
getOutputMatch(outputMatcher: ITerminalOutputMatcher): ITerminalOutputMatch | undefined;
226228
hasOutput(): boolean;

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export class CommandDetectionCapability implements ICommandDetectionCapability {
5858
private _cwd: string | undefined;
5959
private _currentCommand: ICurrentPartialCommand = {};
6060
private _isWindowsPty: boolean = false;
61+
private _aliases: string[][] = [];
6162
private _onCursorMoveListener?: IDisposable;
6263
private _commandMarkers: IMarker[] = [];
6364
private _dimensions: ITerminalDimensions;
@@ -270,6 +271,10 @@ export class CommandDetectionCapability implements ICommandDetectionCapability {
270271
this._isWindowsPty = value;
271272
}
272273

274+
setAliases(value: string): void {
275+
this._aliases = parseAliases(value, this._isWindowsPty);
276+
}
277+
273278
setIsCommandStorageDisabled(): void {
274279
this.__isCommandStorageDisabled = true;
275280
}
@@ -776,3 +781,30 @@ function countNewLines(regex: RegExp): number {
776781
}
777782
return count;
778783
}
784+
785+
function parseAliases(aliasString: string, isWindows?: boolean): string[][] {
786+
const aliases: string[][] = [];
787+
const rows = aliasString.split('\n');
788+
let shellType;
789+
if (isWindows || aliasString.includes('Definition')) {
790+
shellType = 'pwsh';
791+
// Remove the column headers
792+
rows.shift();
793+
} else if (rows.length > 1 && rows[1].startsWith('alias')) {
794+
shellType = 'bash';
795+
} else {
796+
shellType = 'zsh';
797+
}
798+
799+
for (const row of rows) {
800+
if (shellType === 'zsh') {
801+
aliases.push(row.split('='));
802+
} else if (shellType === 'bash') {
803+
aliases.push(row.substring(6).split('='));
804+
} else {
805+
aliases.push(row.split(''));
806+
}
807+
}
808+
console.log(aliases);
809+
return aliases;
810+
}

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

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,10 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati
371371
this.capabilities.get(TerminalCapability.CommandDetection)?.setIsCommandStorageDisabled();
372372
return true;
373373
}
374+
case 'UserAliases': {
375+
this._createOrGetCommandDetection(this._terminal).setAliases(value);
376+
return true;
377+
}
374378
}
375379
}
376380
case VSCodeOscPt.SetMark: {
@@ -548,17 +552,3 @@ export function parseMarkSequence(sequence: string[]): { id?: string; hidden?: b
548552
}
549553
return { id, hidden };
550554
}
551-
552-
function parseAliases(aliasString: string, shellType: string): string[][] {
553-
const aliases: string[][] = [];
554-
const rows = aliasString.split('\n');
555-
for (const row of rows) {
556-
if (shellType === 'zsh') {
557-
aliases.push(row.split('='));
558-
} else if (shellType === 'bash') {
559-
// trim off 'alias '
560-
aliases.push(row.substring(6).split('='));
561-
}
562-
}
563-
return aliases;
564-
}

src/vs/workbench/contrib/terminal/browser/media/shellIntegration-bash.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,4 @@ if [[ -z "${bash_preexec_imported:-}" ]]; then
206206
PROMPT_COMMAND=__vsc_prompt_cmd
207207
fi
208208
fi
209-
echo -ne "\x1b]633;UserAliases;$(alias)"
209+
echo -e "\x1b]633;P;UserAliases=$(alias)"

src/vs/workbench/contrib/terminal/browser/media/shellIntegration-rc.zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,4 @@ add-zsh-hook preexec __vsc_preexec
130130
if [[ $options[login] = off && $USER_ZDOTDIR != $VSCODE_ZDOTDIR ]]; then
131131
ZDOTDIR=$USER_ZDOTDIR
132132
fi
133-
echo -ne "\x1b]633;UserAliases;$(alias)"
133+
echo -e "\x1b]633;P;UserAliases=$(alias)"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,4 @@ function Set-MappedKeyHandlers {
9292
Set-MappedKeyHandler -Chord Shift+End -Sequence 'F12,d'
9393
}
9494
Set-MappedKeyHandlers
95-
[Console]::Write("`e]633;P;Aliases=$(Get-Alias | Select-Object Name, Definition)`a")
95+
[Console]::Write("`e]633;P;UserAliases=$(Get-Alias | Select-Object Name, Definition)`a")

src/vs/workbench/contrib/terminal/electron-sandbox/localPty.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { IPtyHostProcessReplayEvent, ISerializedCommandDetectionCapability } fro
1717
export class LocalPty extends Disposable implements ITerminalChildProcess {
1818
private _inReplay = false;
1919
private _properties: IProcessPropertyMap = {
20-
aliases: '',
2120
cwd: '',
2221
initialCwd: '',
2322
fixedDimensions: { cols: undefined, rows: undefined },

0 commit comments

Comments
 (0)