Skip to content

Commit 67e61c3

Browse files
committed
use a fnction
1 parent f88c515 commit 67e61c3

File tree

2 files changed

+41
-17
lines changed

2 files changed

+41
-17
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,8 @@ function parseAliases(aliasString: string, isWindows?: boolean): string[][] {
806806
} else if (shellType === 'bash') {
807807
aliases.push(row.substring(6).split('='));
808808
} else {
809-
aliases.push(row.split('\s+'));
809+
// to do - way to avoid this filtering?
810+
aliases.push(row.split(' ').filter(s => !!s.trim()));
810811
}
811812
}
812813
console.log(aliases);

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

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,41 @@ if ($ExecutionContext.SessionState.LanguageMode -ne "FullLanguage") {
1616
$Global:__VSCodeOriginalPrompt = $function:Prompt
1717

1818
$Global:__LastHistoryId = -1
19+
function Set-Serialized
20+
{
21+
param ([string] $toSerialize)
22+
$toSerialize = $toSerialize.Replace("\", "\\").Replace("`n", "\x0a").Replace(";", "\x3b")
23+
return $toSerialize
24+
}
1925

20-
21-
function Global:Prompt() {
26+
function Global:Prompt()
27+
{
2228
$FakeCode = [int]!$global:?
2329
$LastHistoryEntry = Get-History -Count 1
2430
# Skip finishing the command if the first command has not yet started
25-
if ($Global:__LastHistoryId -ne -1) {
26-
if ($LastHistoryEntry.Id -eq $Global:__LastHistoryId) {
31+
if ($Global:__LastHistoryId -ne -1)
32+
{
33+
if ($LastHistoryEntry.Id -eq $Global:__LastHistoryId)
34+
{
2735
# Don't provide a command line or exit code if there was no history entry (eg. ctrl+c, enter on no command)
2836
$Result = "`e]633;E`a"
2937
$Result += "`e]633;D`a"
30-
} else {
38+
} else
39+
{
3140
# Command finished command line
3241
# OSC 633 ; A ; <CommandLine?> ST
3342
$Result = "`e]633;E;"
3443
# Sanitize the command line to ensure it can get transferred to the terminal and can be parsed
3544
# correctly. This isn't entirely safe but good for most cases, it's important for the Pt parameter
3645
# to only be composed of _printable_ characters as per the spec.
37-
if ($LastHistoryEntry.CommandLine) {
46+
if ($LastHistoryEntry.CommandLine)
47+
{
3848
$CommandLine = $LastHistoryEntry.CommandLine
39-
} else {
49+
} else
50+
{
4051
$CommandLine = ""
4152
}
42-
$Result += $CommandLine.Replace("\", "\\").Replace("`n", "\x0a").Replace(";", "\x3b")
53+
$Result += Set-Serialized($CommandLine)
4354
$Result += "`a"
4455
# Command finished exit code
4556
# OSC 633 ; D [; <ExitCode>] ST
@@ -51,9 +62,13 @@ function Global:Prompt() {
5162
$Result += "`e]633;A`a"
5263
# Current working directory
5364
# OSC 633 ; <Property>=<Value> ST
54-
$Result += if($pwd.Provider.Name -eq 'FileSystem'){"`e]633;P;Cwd=$($pwd.ProviderPath)`a"}
65+
$Result += if($pwd.Provider.Name -eq 'FileSystem')
66+
{"`e]633;P;Cwd=$($pwd.ProviderPath)`a"
67+
}
5568
# Before running the original prompt, put $? back to what it was:
56-
if ($FakeCode -ne 0) { Write-Error "failure" -ea ignore }
69+
if ($FakeCode -ne 0)
70+
{ Write-Error "failure" -ea ignore
71+
}
5772
# Run the original prompt
5873
$Result += $Global:__VSCodeOriginalPrompt.Invoke()
5974
# Write command started
@@ -64,9 +79,11 @@ function Global:Prompt() {
6479

6580
# Only send the command executed sequence when PSReadLine is loaded, if not shell integration should
6681
# still work thanks to the command line sequence
67-
if (Get-Module -Name PSReadLine) {
82+
if (Get-Module -Name PSReadLine)
83+
{
6884
$__VSCodeOriginalPSConsoleHostReadLine = $function:PSConsoleHostReadLine
69-
function Global:PSConsoleHostReadLine {
85+
function Global:PSConsoleHostReadLine
86+
{
7087
$tmp = $__VSCodeOriginalPSConsoleHostReadLine.Invoke()
7188
# Write command executed sequence directly to Console to avoid the new line from Write-Host
7289
[Console]::Write("`e]633;C`a")
@@ -78,21 +95,27 @@ if (Get-Module -Name PSReadLine) {
7895
[Console]::Write("`e]633;P;IsWindows=$($IsWindows)`a")
7996

8097
# Set always on key handlers which map to default VS Code keybindings
81-
function Set-MappedKeyHandler {
98+
function Set-MappedKeyHandler
99+
{
82100
param ([string[]] $Chord, [string[]]$Sequence)
83101
$Handler = $(Get-PSReadLineKeyHandler -Chord $Chord | Select-Object -First 1)
84-
if ($Handler) {
102+
if ($Handler)
103+
{
85104
Set-PSReadLineKeyHandler -Chord $Sequence -Function $Handler.Function
86105
}
87106
}
88-
function Set-MappedKeyHandlers {
107+
function Set-MappedKeyHandlers
108+
{
89109
Set-MappedKeyHandler -Chord Ctrl+Spacebar -Sequence 'F12,a'
90110
Set-MappedKeyHandler -Chord Alt+Spacebar -Sequence 'F12,b'
91111
Set-MappedKeyHandler -Chord Shift+Enter -Sequence 'F12,c'
92112
Set-MappedKeyHandler -Chord Shift+End -Sequence 'F12,d'
93113
}
114+
94115
Set-MappedKeyHandlers
95116
$result = $(Get-Alias | Select-Object Name, Definition)
96117
$resultStr = Out-String -InputObject $result
97-
$resultStr = $resultStr.Replace("\", "\\").Replace("`n", "\x0a").Replace(";", "\x3b")
118+
$resultStr = Set-Serialized($resultStr)
98119
[Console]::Write("`e]633;P;UserAliases=$resultStr`a")
120+
121+

0 commit comments

Comments
 (0)