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