4
4
# ---------------------------------------------------------------------------------------------
5
5
6
6
# Prevent installing more than once per session
7
- if (Test-Path variable:global :__VSCodeState.OriginalPrompt) {
7
+ if (Test-Path variable:Script :__VSCodeState.OriginalPrompt) {
8
8
return ;
9
9
}
10
10
@@ -13,7 +13,7 @@ if ($ExecutionContext.SessionState.LanguageMode -ne "FullLanguage") {
13
13
return ;
14
14
}
15
15
16
- $Global :__VSCodeState = @ {
16
+ $Script :__VSCodeState = @ {
17
17
OriginalPrompt = $function: Prompt
18
18
LastHistoryId = -1
19
19
IsInExecution = $false
@@ -24,21 +24,21 @@ $Global:__VSCodeState = @{
24
24
}
25
25
26
26
# Store the nonce in script scope and unset the global
27
- $Global :__VSCodeState.Nonce = $env: VSCODE_NONCE
27
+ $Script :__VSCodeState.Nonce = $env: VSCODE_NONCE
28
28
$env: VSCODE_NONCE = $null
29
29
30
- $Global :__VSCodeState.IsStable = $env: VSCODE_STABLE
30
+ $Script :__VSCodeState.IsStable = $env: VSCODE_STABLE
31
31
$env: VSCODE_STABLE = $null
32
32
33
33
$__vscode_shell_env_reporting = $env: VSCODE_SHELL_ENV_REPORTING
34
34
$env: VSCODE_SHELL_ENV_REPORTING = $null
35
35
if ($__vscode_shell_env_reporting ) {
36
- $Global :__VSCodeState.EnvVarsToReport = $__vscode_shell_env_reporting.Split (' ,' )
36
+ $Script :__VSCodeState.EnvVarsToReport = $__vscode_shell_env_reporting.Split (' ,' )
37
37
}
38
38
Remove-Variable - Name __vscode_shell_env_reporting - ErrorAction SilentlyContinue
39
39
40
40
$osVersion = [System.Environment ]::OSVersion.Version
41
- $Global :__VSCodeState.IsWindows10 = $IsWindows -and $osVersion.Major -eq 10 -and $osVersion.Minor -eq 0 -and $osVersion.Build -lt 22000
41
+ $Script :__VSCodeState.IsWindows10 = $IsWindows -and $osVersion.Major -eq 10 -and $osVersion.Minor -eq 0 -and $osVersion.Build -lt 22000
42
42
Remove-Variable - Name osVersion - ErrorAction SilentlyContinue
43
43
44
44
if ($env: VSCODE_ENV_REPLACE ) {
@@ -86,9 +86,9 @@ function Global:Prompt() {
86
86
$Result = " "
87
87
# Skip finishing the command if the first command has not yet started or an execution has not
88
88
# yet begun
89
- if ($Global :__VSCodeState.LastHistoryId -ne -1 -and $Global :__VSCodeState.IsInExecution -eq $true ) {
90
- $Global :__VSCodeState.IsInExecution = $false
91
- if ($LastHistoryEntry.Id -eq $Global :__VSCodeState.LastHistoryId ) {
89
+ if ($Script :__VSCodeState.LastHistoryId -ne -1 -and $Script :__VSCodeState.IsInExecution -eq $true ) {
90
+ $Script :__VSCodeState.IsInExecution = $false
91
+ if ($LastHistoryEntry.Id -eq $Script :__VSCodeState.LastHistoryId ) {
92
92
# Don't provide a command line or exit code if there was no history entry (eg. ctrl+c, enter on no command)
93
93
$Result += " $ ( [char ]0x1b ) ]633;D`a "
94
94
}
@@ -107,34 +107,34 @@ function Global:Prompt() {
107
107
108
108
# Send current environment variables as JSON
109
109
# OSC 633 ; EnvJson ; <Environment> ; <Nonce>
110
- if ($Global :__VSCodeState.EnvVarsToReport.Count -gt 0 ) {
110
+ if ($Script :__VSCodeState.EnvVarsToReport.Count -gt 0 ) {
111
111
$envMap = @ {}
112
- foreach ($varName in $Global :__VSCodeState.EnvVarsToReport ) {
112
+ foreach ($varName in $Script :__VSCodeState.EnvVarsToReport ) {
113
113
if (Test-Path " env:$varName " ) {
114
114
$envMap [$varName ] = (Get-Item " env:$varName " ).Value
115
115
}
116
116
}
117
117
$envJson = $envMap | ConvertTo-Json - Compress
118
- $Result += " $ ( [char ]0x1b ) ]633;EnvJson;$ ( __VSCode- Escape- Value $envJson ) ;$ ( $Global :__VSCodeState.Nonce ) `a "
118
+ $Result += " $ ( [char ]0x1b ) ]633;EnvJson;$ ( __VSCode- Escape- Value $envJson ) ;$ ( $Script :__VSCodeState.Nonce ) `a "
119
119
}
120
120
121
121
# Before running the original prompt, put $? back to what it was:
122
122
if ($FakeCode -ne 0 ) {
123
123
Write-Error " failure" - ea ignore
124
124
}
125
125
# Run the original prompt
126
- $OriginalPrompt += $Global :__VSCodeState.OriginalPrompt.Invoke ()
126
+ $OriginalPrompt += $Script :__VSCodeState.OriginalPrompt.Invoke ()
127
127
$Result += $OriginalPrompt
128
128
129
129
# Prompt
130
130
# OSC 633 ; <Property>=<Value> ST
131
- if ($Global :__VSCodeState.IsStable -eq " 0" ) {
131
+ if ($Script :__VSCodeState.IsStable -eq " 0" ) {
132
132
$Result += " $ ( [char ]0x1b ) ]633;P;Prompt=$ ( __VSCode- Escape- Value $OriginalPrompt ) `a "
133
133
}
134
134
135
135
# Write command started
136
136
$Result += " $ ( [char ]0x1b ) ]633;B`a "
137
- $Global :__VSCodeState.LastHistoryId = $LastHistoryEntry.Id
137
+ $Script :__VSCodeState.LastHistoryId = $LastHistoryEntry.Id
138
138
return $Result
139
139
}
140
140
@@ -154,19 +154,19 @@ elseif ((Test-Path variable:global:GitPromptSettings) -and $Global:GitPromptSett
154
154
if (Get-Module - Name PSReadLine) {
155
155
[Console ]::Write(" $ ( [char ]0x1b ) ]633;P;HasRichCommandDetection=True`a " )
156
156
157
- $Global :__VSCodeState.OriginalPSConsoleHostReadLine = $function: PSConsoleHostReadLine
157
+ $Script :__VSCodeState.OriginalPSConsoleHostReadLine = $function: PSConsoleHostReadLine
158
158
function Global :PSConsoleHostReadLine {
159
- $CommandLine = $Global :__VSCodeState.OriginalPSConsoleHostReadLine.Invoke ()
160
- $Global :__VSCodeState.IsInExecution = $true
159
+ $CommandLine = $Script :__VSCodeState.OriginalPSConsoleHostReadLine.Invoke ()
160
+ $Script :__VSCodeState.IsInExecution = $true
161
161
162
162
# Command line
163
163
# OSC 633 ; E [; <CommandLine> [; <Nonce>]] ST
164
164
$Result = " $ ( [char ]0x1b ) ]633;E;"
165
165
$Result += $ (__VSCode- Escape- Value $CommandLine )
166
166
# Only send the nonce if the OS is not Windows 10 as it seems to echo to the terminal
167
167
# sometimes
168
- if ($Global :__VSCodeState.IsWindows10 -eq $false ) {
169
- $Result += " ;$ ( $Global :__VSCodeState.Nonce ) "
168
+ if ($Script :__VSCodeState.IsWindows10 -eq $false ) {
169
+ $Result += " ;$ ( $Script :__VSCodeState.Nonce ) "
170
170
}
171
171
$Result += " `a "
172
172
@@ -181,9 +181,9 @@ if (Get-Module -Name PSReadLine) {
181
181
}
182
182
183
183
# Set ContinuationPrompt property
184
- $Global :__VSCodeState.ContinuationPrompt = (Get-PSReadLineOption ).ContinuationPrompt
185
- if ($Global :__VSCodeState.ContinuationPrompt ) {
186
- [Console ]::Write(" $ ( [char ]0x1b ) ]633;P;ContinuationPrompt=$ ( __VSCode- Escape- Value $Global :__VSCodeState.ContinuationPrompt ) `a " )
184
+ $Script :__VSCodeState.ContinuationPrompt = (Get-PSReadLineOption ).ContinuationPrompt
185
+ if ($Script :__VSCodeState.ContinuationPrompt ) {
186
+ [Console ]::Write(" $ ( [char ]0x1b ) ]633;P;ContinuationPrompt=$ ( __VSCode- Escape- Value $Script :__VSCodeState.ContinuationPrompt ) `a " )
187
187
}
188
188
}
189
189
0 commit comments