@@ -16,27 +16,22 @@ if ($ExecutionContext.SessionState.LanguageMode -ne "FullLanguage") {
16
16
$Global :__VSCodeOriginalPrompt = $function: Prompt
17
17
18
18
$Global :__LastHistoryId = -1
19
- function Set-Serialized
20
- {
19
+ function Set-Serialized {
21
20
param ([string ] $toSerialize )
22
21
$toSerialize = $toSerialize.Replace (" \" , " \\" ).Replace(" `n " , " \x0a" ).Replace(" ;" , " \x3b" )
23
22
return $toSerialize
24
23
}
25
24
26
- function Global :Prompt ()
27
- {
25
+ function Global :Prompt () {
28
26
$FakeCode = [int ]! $global :?
29
27
$LastHistoryEntry = Get-History - Count 1
30
28
# Skip finishing the command if the first command has not yet started
31
- if ($Global :__LastHistoryId -ne -1 )
32
- {
33
- if ($LastHistoryEntry.Id -eq $Global :__LastHistoryId )
34
- {
29
+ if ($Global :__LastHistoryId -ne -1 ) {
30
+ if ($LastHistoryEntry.Id -eq $Global :__LastHistoryId ) {
35
31
# Don't provide a command line or exit code if there was no history entry (eg. ctrl+c, enter on no command)
36
32
$Result = " $ ( [char ]0x1b ) ]633;E`a "
37
33
$Result += " $ ( [char ]0x1b ) ]633;D`a "
38
- } else
39
- {
34
+ } else {
40
35
# Command finished command line
41
36
# OSC 633 ; A ; <CommandLine?> ST
42
37
$Result = " $ ( [char ]0x1b ) ]633;E;"
@@ -64,9 +59,9 @@ function Global:Prompt()
64
59
# OSC 633 ; <Property>=<Value> ST
65
60
$Result += if ($pwd.Provider.Name -eq ' FileSystem' ){" $ ( [char ]0x1b ) ]633;P;Cwd=$ ( $pwd.ProviderPath ) `a " }
66
61
# Before running the original prompt, put $? back to what it was:
67
- if ($FakeCode -ne 0 )
68
- { Write-Error " failure" - ea ignore
69
- }
62
+ if ($FakeCode -ne 0 ) {
63
+ Write-Error " failure" - ea ignore
64
+ }
70
65
# Run the original prompt
71
66
$Result += $Global :__VSCodeOriginalPrompt.Invoke ()
72
67
# Write command started
@@ -77,11 +72,9 @@ function Global:Prompt()
77
72
78
73
# Only send the command executed sequence when PSReadLine is loaded, if not shell integration should
79
74
# still work thanks to the command line sequence
80
- if (Get-Module - Name PSReadLine)
81
- {
75
+ if (Get-Module - Name PSReadLine) {
82
76
$__VSCodeOriginalPSConsoleHostReadLine = $function: PSConsoleHostReadLine
83
- function Global :PSConsoleHostReadLine
84
- {
77
+ function Global :PSConsoleHostReadLine {
85
78
$tmp = $__VSCodeOriginalPSConsoleHostReadLine.Invoke ()
86
79
# Write command executed sequence directly to Console to avoid the new line from Write-Host
87
80
[Console ]::Write(" $ ( [char ]0x1b ) ]633;C`a " )
@@ -93,24 +86,24 @@ if (Get-Module -Name PSReadLine)
93
86
[Console ]::Write(" $ ( [char ]0x1b ) ]633;P;IsWindows=$ ( $IsWindows ) `a " )
94
87
95
88
# Set always on key handlers which map to default VS Code keybindings
96
- function Set-MappedKeyHandler
97
- {
89
+ function Set-MappedKeyHandler {
98
90
param ([string []] $Chord , [string []]$Sequence )
99
91
$Handler = $ (Get-PSReadLineKeyHandler - Chord $Chord | Select-Object - First 1 )
100
- if ($Handler )
101
- {
92
+ if ($Handler ) {
102
93
Set-PSReadLineKeyHandler - Chord $Sequence - Function $Handler.Function
103
94
}
104
95
}
105
- function Set-MappedKeyHandlers
106
- {
96
+
97
+ function Set-MappedKeyHandlers {
107
98
Set-MappedKeyHandler - Chord Ctrl+ Spacebar - Sequence ' F12,a'
108
99
Set-MappedKeyHandler - Chord Alt+ Spacebar - Sequence ' F12,b'
109
100
Set-MappedKeyHandler - Chord Shift+ Enter - Sequence ' F12,c'
110
101
Set-MappedKeyHandler - Chord Shift+ End - Sequence ' F12,d'
111
102
}
112
103
113
104
Set-MappedKeyHandlers
105
+
106
+ # Send aliases to the terminal
114
107
$result = $ (Get-Alias | Select-Object Name, Definition)
115
108
$resultStr = Out-String - InputObject $result
116
109
$resultStr = Set-Serialized ($resultStr )
0 commit comments