Skip to content

Commit dd48c7f

Browse files
authored
Merge pull request #251303 from microsoft/tyriar/250000
Move shell integration ps1 into module
2 parents 80f28ae + 3962d9c commit dd48c7f

File tree

7 files changed

+32
-35
lines changed

7 files changed

+32
-35
lines changed

build/azure-pipelines/win32/codesign.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/azure-pipelines/win32/codesign.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async function main() {
1919
// 2. Codesign Powershell scripts
2020
// 3. Codesign context menu appx package (insiders only)
2121
const codesignTask1 = spawnCodesignProcess(esrpCliDLLPath, 'sign-windows', codeSigningFolderPath, '*.dll,*.exe,*.node');
22-
const codesignTask2 = spawnCodesignProcess(esrpCliDLLPath, 'sign-windows-appx', codeSigningFolderPath, '*.ps1');
22+
const codesignTask2 = spawnCodesignProcess(esrpCliDLLPath, 'sign-windows-appx', codeSigningFolderPath, '*.ps1,*.psm1');
2323
const codesignTask3 = process.env['VSCODE_QUALITY'] === 'insider'
2424
? spawnCodesignProcess(esrpCliDLLPath, 'sign-windows-appx', codeSigningFolderPath, '*.appx')
2525
: undefined;

build/gulpfile.reh.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ const serverResourceIncludes = [
6767
'out-build/vs/workbench/contrib/externalTerminal/**/*.scpt',
6868

6969
// Terminal shell integration
70-
'out-build/vs/workbench/contrib/terminal/common/scripts/shellIntegration.ps1',
71-
'out-build/vs/workbench/contrib/terminal/common/scripts/CodeTabExpansion.psm1',
72-
'out-build/vs/workbench/contrib/terminal/common/scripts/GitTabExpansion.psm1',
70+
'out-build/vs/workbench/contrib/terminal/common/scripts/shellIntegration.psm1',
7371
'out-build/vs/workbench/contrib/terminal/common/scripts/shellIntegration-bash.sh',
7472
'out-build/vs/workbench/contrib/terminal/common/scripts/shellIntegration-env.zsh',
7573
'out-build/vs/workbench/contrib/terminal/common/scripts/shellIntegration-profile.zsh',

build/gulpfile.vscode.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ const vscodeResourceIncludes = [
7575

7676
// Terminal shell integration
7777
'out-build/vs/workbench/contrib/terminal/common/scripts/*.fish',
78-
'out-build/vs/workbench/contrib/terminal/common/scripts/*.ps1',
7978
'out-build/vs/workbench/contrib/terminal/common/scripts/*.psm1',
8079
'out-build/vs/workbench/contrib/terminal/common/scripts/*.sh',
8180
'out-build/vs/workbench/contrib/terminal/common/scripts/*.zsh',

src/vs/platform/terminal/node/terminalEnvironment.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,10 @@ enum ShellIntegrationExecutable {
338338

339339
const shellIntegrationArgs: Map<ShellIntegrationExecutable, string[]> = new Map();
340340
// The try catch swallows execution policy errors in the case of the archive distributable
341-
shellIntegrationArgs.set(ShellIntegrationExecutable.WindowsPwsh, ['-noexit', '-command', 'try { . \"{0}\\out\\vs\\workbench\\contrib\\terminal\\common\\scripts\\shellIntegration.ps1\" } catch {}{1}']);
342-
shellIntegrationArgs.set(ShellIntegrationExecutable.WindowsPwshLogin, ['-l', '-noexit', '-command', 'try { . \"{0}\\out\\vs\\workbench\\contrib\\terminal\\common\\scripts\\shellIntegration.ps1\" } catch {}{1}']);
343-
shellIntegrationArgs.set(ShellIntegrationExecutable.Pwsh, ['-noexit', '-command', '. "{0}/out/vs/workbench/contrib/terminal/common/scripts/shellIntegration.ps1"{1}']);
344-
shellIntegrationArgs.set(ShellIntegrationExecutable.PwshLogin, ['-l', '-noexit', '-command', '. "{0}/out/vs/workbench/contrib/terminal/common/scripts/shellIntegration.ps1"']);
341+
shellIntegrationArgs.set(ShellIntegrationExecutable.WindowsPwsh, ['-noexit', '-command', 'try { Import-Module \"{0}\\out\\vs\\workbench\\contrib\\terminal\\common\\scripts\\shellIntegration.psm1\" } catch {}{1}']);
342+
shellIntegrationArgs.set(ShellIntegrationExecutable.WindowsPwshLogin, ['-l', '-noexit', '-command', 'try { Import-Module \"{0}\\out\\vs\\workbench\\contrib\\terminal\\common\\scripts\\shellIntegration.psm1\" } catch {}{1}']);
343+
shellIntegrationArgs.set(ShellIntegrationExecutable.Pwsh, ['-noexit', '-command', 'Import-Module "{0}/out/vs/workbench/contrib/terminal/common/scripts/shellIntegration.psm1"{1}']);
344+
shellIntegrationArgs.set(ShellIntegrationExecutable.PwshLogin, ['-l', '-noexit', '-command', 'Import-Module "{0}/out/vs/workbench/contrib/terminal/common/scripts/shellIntegration.psm1"']);
345345
shellIntegrationArgs.set(ShellIntegrationExecutable.Zsh, ['-i']);
346346
shellIntegrationArgs.set(ShellIntegrationExecutable.ZshLogin, ['-il']);
347347
shellIntegrationArgs.set(ShellIntegrationExecutable.Bash, ['--init-file', '{0}/out/vs/workbench/contrib/terminal/common/scripts/shellIntegration-bash.sh']);

src/vs/platform/terminal/test/node/terminalEnvironment.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ suite('platform - terminalEnvironment', async () => {
4848
// These tests are only expected to work on Windows 10 build 18309 and above
4949
(getWindowsBuildNumber() < 18309 ? suite.skip : suite)('pwsh', async () => {
5050
const expectedPs1 = process.platform === 'win32'
51-
? `try { . "${repoRoot}\\out\\vs\\workbench\\contrib\\terminal\\common\\scripts\\shellIntegration.ps1" } catch {}`
52-
: `. "${repoRoot}/out/vs/workbench/contrib/terminal/common/scripts/shellIntegration.ps1"`;
51+
? `try { Import-Module "${repoRoot}\\out\\vs\\workbench\\contrib\\terminal\\common\\scripts\\shellIntegration.psm1" } catch {}`
52+
: `Import-Module "${repoRoot}/out/vs/workbench/contrib/terminal/common/scripts/shellIntegration.psm1"`;
5353
suite('should override args', async () => {
5454
const enabledExpectedResult = Object.freeze<IShellIntegrationConfigInjection>({
5555
type: 'injection',

src/vs/workbench/contrib/terminal/common/scripts/shellIntegration.ps1 renamed to src/vs/workbench/contrib/terminal/common/scripts/shellIntegration.psm1

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# ---------------------------------------------------------------------------------------------
55

66
# Prevent installing more than once per session
7-
if (Test-Path variable:global:__VSCodeState.OriginalPrompt) {
7+
if (Test-Path variable:Script:__VSCodeState.OriginalPrompt) {
88
return;
99
}
1010

@@ -13,7 +13,7 @@ if ($ExecutionContext.SessionState.LanguageMode -ne "FullLanguage") {
1313
return;
1414
}
1515

16-
$Global:__VSCodeState = @{
16+
$Script:__VSCodeState = @{
1717
OriginalPrompt = $function:Prompt
1818
LastHistoryId = -1
1919
IsInExecution = $false
@@ -24,21 +24,21 @@ $Global:__VSCodeState = @{
2424
}
2525

2626
# Store the nonce in script scope and unset the global
27-
$Global:__VSCodeState.Nonce = $env:VSCODE_NONCE
27+
$Script:__VSCodeState.Nonce = $env:VSCODE_NONCE
2828
$env:VSCODE_NONCE = $null
2929

30-
$Global:__VSCodeState.IsStable = $env:VSCODE_STABLE
30+
$Script:__VSCodeState.IsStable = $env:VSCODE_STABLE
3131
$env:VSCODE_STABLE = $null
3232

3333
$__vscode_shell_env_reporting = $env:VSCODE_SHELL_ENV_REPORTING
3434
$env:VSCODE_SHELL_ENV_REPORTING = $null
3535
if ($__vscode_shell_env_reporting) {
36-
$Global:__VSCodeState.EnvVarsToReport = $__vscode_shell_env_reporting.Split(',')
36+
$Script:__VSCodeState.EnvVarsToReport = $__vscode_shell_env_reporting.Split(',')
3737
}
3838
Remove-Variable -Name __vscode_shell_env_reporting -ErrorAction SilentlyContinue
3939

4040
$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
4242
Remove-Variable -Name osVersion -ErrorAction SilentlyContinue
4343

4444
if ($env:VSCODE_ENV_REPLACE) {
@@ -86,9 +86,9 @@ function Global:Prompt() {
8686
$Result = ""
8787
# Skip finishing the command if the first command has not yet started or an execution has not
8888
# 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) {
9292
# Don't provide a command line or exit code if there was no history entry (eg. ctrl+c, enter on no command)
9393
$Result += "$([char]0x1b)]633;D`a"
9494
}
@@ -107,34 +107,34 @@ function Global:Prompt() {
107107

108108
# Send current environment variables as JSON
109109
# OSC 633 ; EnvJson ; <Environment> ; <Nonce>
110-
if ($Global:__VSCodeState.EnvVarsToReport.Count -gt 0) {
110+
if ($Script:__VSCodeState.EnvVarsToReport.Count -gt 0) {
111111
$envMap = @{}
112-
foreach ($varName in $Global:__VSCodeState.EnvVarsToReport) {
112+
foreach ($varName in $Script:__VSCodeState.EnvVarsToReport) {
113113
if (Test-Path "env:$varName") {
114114
$envMap[$varName] = (Get-Item "env:$varName").Value
115115
}
116116
}
117117
$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"
119119
}
120120

121121
# Before running the original prompt, put $? back to what it was:
122122
if ($FakeCode -ne 0) {
123123
Write-Error "failure" -ea ignore
124124
}
125125
# Run the original prompt
126-
$OriginalPrompt += $Global:__VSCodeState.OriginalPrompt.Invoke()
126+
$OriginalPrompt += $Script:__VSCodeState.OriginalPrompt.Invoke()
127127
$Result += $OriginalPrompt
128128

129129
# Prompt
130130
# OSC 633 ; <Property>=<Value> ST
131-
if ($Global:__VSCodeState.IsStable -eq "0") {
131+
if ($Script:__VSCodeState.IsStable -eq "0") {
132132
$Result += "$([char]0x1b)]633;P;Prompt=$(__VSCode-Escape-Value $OriginalPrompt)`a"
133133
}
134134

135135
# Write command started
136136
$Result += "$([char]0x1b)]633;B`a"
137-
$Global:__VSCodeState.LastHistoryId = $LastHistoryEntry.Id
137+
$Script:__VSCodeState.LastHistoryId = $LastHistoryEntry.Id
138138
return $Result
139139
}
140140

@@ -154,19 +154,19 @@ elseif ((Test-Path variable:global:GitPromptSettings) -and $Global:GitPromptSett
154154
if (Get-Module -Name PSReadLine) {
155155
[Console]::Write("$([char]0x1b)]633;P;HasRichCommandDetection=True`a")
156156

157-
$Global:__VSCodeState.OriginalPSConsoleHostReadLine = $function:PSConsoleHostReadLine
157+
$Script:__VSCodeState.OriginalPSConsoleHostReadLine = $function:PSConsoleHostReadLine
158158
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
161161

162162
# Command line
163163
# OSC 633 ; E [; <CommandLine> [; <Nonce>]] ST
164164
$Result = "$([char]0x1b)]633;E;"
165165
$Result += $(__VSCode-Escape-Value $CommandLine)
166166
# Only send the nonce if the OS is not Windows 10 as it seems to echo to the terminal
167167
# 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)"
170170
}
171171
$Result += "`a"
172172

@@ -181,9 +181,9 @@ if (Get-Module -Name PSReadLine) {
181181
}
182182

183183
# 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")
187187
}
188188
}
189189

0 commit comments

Comments
 (0)