-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMicrosoft.VSCode_profile.ps1
More file actions
101 lines (92 loc) · 7.79 KB
/
Microsoft.VSCode_profile.ps1
File metadata and controls
101 lines (92 loc) · 7.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# ~/.config/powershell/Microsoft.VSCode_profile.ps1 - Source: https://github.com/jpawlowski/devcontainer-features/src/powershell-extended/dotfiles/.config/powershell/Microsoft.VSCode_profile.ps1
# This profile is executed by the VSCode Integrated Terminal on startup.
#
# Purpose:
# This file is intended for settings and configurations that should apply only to the VSCode Integrated Terminal
# (also known as the terminal section of VSCode with the display name "PowerShell Extension").
# It should include visual configurations. Non-visual configurations should be placed in:
# - profile.ps1
#
# Note:
# This file is only executed by the VSCode Integrated Terminal, not the PowerShell console host.
# See Microsoft.PowerShell_profile.ps1 for settings that apply to the PowerShell console host.
#
# Visual configurations include:
# - Prompt customization
# - Themes (e.g., Oh My Posh themes)
# - Host-specific settings (e.g., settings specific to the VSCode Integrated Terminal)
# - Command line completion modules and PSReadLine predictor plugins (While not visual, these are included here to enhance the user experience in the VSCode Integrated Terminal)
#
# Performance Considerations:
# When adding command line completion modules or PSReadLine predictor plugins, ensure they do not degrade performance during profile load.
# This is crucial because when dev containers start and PowerShell is configured as the default shell for the user (not the VSCode settings),
# VSCode may report slow response times during the userEnvProbe process.
#
# About userEnvProbe:
# The userEnvProbe process is used by VSCode to gather environment variables and other shell settings during the startup of a dev container.
# This process occurs before any terminal is started and ensures that environment settings from devcontainer.json (such as remoteEnv) are correctly applied.
# It is important for this process to be quick to ensure a smooth startup experience for the dev container.
# Keeping the profile lightweight and efficient helps avoid performance issues during this probe.
#
# Note:
# Visual configurations are settings that affect the appearance of the VSCode Integrated Terminal.
# For an explanation of the difference between a PowerShell host and a terminal emulator, see profile.ps1.
#Requires -Version 7.2
try {
if ($Error) { return } # Skip if there was an error loading the profile before
__PSProfile-Initialize-Profile
__PSProfile-Write-ProfileLoadMessage "📝 Applying configurations for $($PSStyle.Bold)PowerShell Extension$($PSStyle.BoldOff)." -ForegroundColor DarkCyan
if (__PSProfile-Assert-IsUserInteractiveShell) {
#region Import Modules =================================================
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_TERMINAL_COMPLETION_AZURECLI') -eq $true) { __PSProfile-Register-ArgumentCompleter-AzureCli }
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_TERMINAL_COMPLETION_GITHUBCLI') -eq $true -and $null -ne (Get-Command -Name gh -CommandType Application -ErrorAction Ignore)) { Invoke-Expression -Command $(gh completion -s powershell | Out-String) }
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_TERMINAL_COMPLETION_POSHGIT') -eq $true) { __PSProfile-Import-ModuleAndInstallIfMissing -Name posh-git }
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_TERMINAL_COMPLETION_PSFZF') -eq $true -and $null -ne (Get-Command -Name fzf -CommandType Application -ErrorAction Ignore)) { __PSProfile-Import-ModuleAndInstallIfMissing -Name PSFzf }
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_TERMINAL_COMPLETION_UNIX') -eq $true) { __PSProfile-Import-ModuleAndInstallIfMissing -Name Microsoft.PowerShell.UnixTabCompletion }
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_TERMINAL_COMPLETION_PREDICTOR') -eq $true) { __PSProfile-Import-ModuleAndInstallIfMissing -Name CompletionPredictor }
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_TERMINAL_COMPLETION_PREDICTOR_AZ') -eq $true -and $null -ne (Get-Module -Name Az.Accounts -ListAvailable)) { __PSProfile-Import-ModuleAndInstallIfMissing -Name Az.Tools.Predictor }
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_TERMINAL_ICONS') -eq $true) { __PSProfile-Import-ModuleAndInstallIfMissing -Name Terminal-Icons }
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_TERMINAL_Z') -eq $true) { __PSProfile-Import-ModuleAndInstallIfMissing -Name z }
#endregion Import Modules ----------------------------------------------
#region PSReadLine predictor plugins ===================================
$__PSProfilePSReadLineOptions = @{}
$__PSProfileEnvPSReadlinePredictionSource = [System.Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_PSREADLINE_PREDICTION_SOURCE')
$__PSProfileEnvPSReadlinePredictionViewStyle = [System.Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_PSREADLINE_PREDICTION_VIEWSTYLE')
if ($null -ne $__PSProfileEnvPSReadlinePredictionSource) { $__PSProfilePSReadLineOptions.PredictionSource = $__PSProfileEnvPSReadlinePredictionSource }
if ($null -ne $__PSProfileEnvPSReadlinePredictionViewStyle) { $__PSProfilePSReadLineOptions.PredictionViewStyle = $__PSProfileEnvPSReadlinePredictionViewStyle }
if ($__PSProfilePSReadLineOptions.Count -gt 0) { Set-PSReadLineOption @__PSProfilePSReadLineOptions }
#endregion PSReadLine --------------------------------------------------
#region Environment ====================================================
$__PSProfileEnvAutoUpdateModuleHelp = [System.Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_AUTOUPDATE_MODULEHELP')
if ($null -eq $__PSProfileEnvAutoUpdateModuleHelp -or $__PSProfileEnvAutoUpdateModuleHelp -eq $true) { __PSProfile-Update-Help }
#endregion Environment -------------------------------------------------
#region Oh My Posh =====================================================
$__PSProfileEnvOhMyPoshTheme = [System.Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_POSH_THEME')
if ($null -ne $__PSProfileEnvOhMyPoshTheme) { __PSProfile-Enable-OhMyPosh-Theme -ThemeName $__PSProfileEnvOhMyPoshTheme } else { __PSProfile-Enable-OhMyPosh-Theme }
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_VSCODE_TERMINAL_COMPLETION_POSH') -eq $true -and $null -ne [System.Environment]::GetEnvironmentVariable('POSH_PID')) { Invoke-Expression -Command $(oh-my-posh completion powershell | Out-String) }
#endregion Oh My Posh --------------------------------------------------
}
#region Custom Profile =====================================================
#
# Hint:
# To load your own custom profile, you may create a directory named 'Microsoft.VSCode_profile.d' in the same directory as this file.
# Then, place your custom profile files in the 'Microsoft.VSCode_profile.d' directory to load them automatically.
#
$__PSProfileDirectoryPath = [System.IO.Path]::ChangeExtension($MyInvocation.MyCommand.Path, 'd')
if ([System.IO.Directory]::Exists($__PSProfileDirectoryPath)) {
$__PSProfileCustomProfileFiles = [System.IO.Directory]::GetFiles($__PSProfileDirectoryPath, '*.ps1')
[System.Array]::Sort($__PSProfileCustomProfileFiles)
foreach ($__PSProfileCustomProfileFile in $__PSProfileCustomProfileFiles) {
. $__PSProfileCustomProfileFile
}
}
#endregion Custom Profile --------------------------------------------------
}
catch {
__PSProfile-Write-ProfileLoadMessage "`n❌ Interrupting profile load process.`n" -ForegroundColor DarkRed
Write-Error "An error occurred while loading the user profile." -ErrorAction Continue
throw
}
finally {
__PSProfile-Clear-Environment
}