-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPROFILE.AllUsersAllHosts.ps1
More file actions
267 lines (233 loc) · 13.8 KB
/
PROFILE.AllUsersAllHosts.ps1
File metadata and controls
267 lines (233 loc) · 13.8 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# /opt/microsoft/powershell/7/profile.ps1 - Source: https://github.com/jpawlowski/devcontainer-features/src/powershell-extended/PROFILE.AllUsersAllHosts.ps1
# This profile is executed by all PowerShell hosts (e.g., PowerShell console, VSCode Integrated Terminal) on startup for all users.
#
# Purpose:
# This file is intended for settings and configurations that should apply to all PowerShell hosts for all users.
# It should include non-visual configurations that are essential for all users. Visual configurations should typically be left to user-specific profiles.
#
# Non-visual configurations include:
# - Functions
# - Module imports
# - Aliases
# - Environment variables
# - PSReadLine configurations (e.g., key bindings, edit mode)
# - Exception: PSReadLine predictor plugins and other shell completion modules should be placed in host-specific profiles to improve performance.
#
# Note:
# Non-visual configurations are settings that affect the behavior of PowerShell itself, regardless of the host.
# A "host" in this context refers to the application or interface where PowerShell commands are executed, such as the PowerShell console or the VSCode Integrated Terminal.
#
# Per-user profiles:
# - $PROFILE.CurrentUserAllHosts: ~/.config/powershell/profile.ps1
# This profile is executed by all PowerShell hosts on startup for the current user.
# It should include user-specific non-visual configurations and visual configurations.
# - $PROFILE.CurrentUserCurrentHost: ~/.config/powershell/Microsoft.VSCode_profile.ps1
# This profile is executed by the VSCode Integrated Terminal on startup for the current user.
# It should include user-specific visual configurations for the VSCode Integrated Terminal.
#
# Best Practices:
# - Global profiles should focus on essential non-visual configurations that apply to all users to avoid redundancy.
# - Visual configurations and user-specific settings should be placed in user-specific profiles to improve performance and customization.
# - Avoid duplicating settings in global and user-specific profiles to prevent unnecessary loading and potential conflicts.
#Requires -Version 7.0
try {
#region Functions ==============================================================
$__PSProfileFunctionsPath = [System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName($PROFILE.AllUsersAllHosts), 'profile.functions.ps1')
if ([System.IO.File]::Exists($__PSProfileFunctionsPath)) { . $__PSProfileFunctionsPath } else { throw "Profile functions file not found at $__PSProfileFunctionsPath" }
__PSProfile-Initialize-Profile
#endregion Functions -----------------------------------------------------------
if ($IsWindows) { return } # This global profile is for *nix only
#region Script Variables =======================================================
$__PSProfileEnvPathOriginal = [System.Environment]::GetEnvironmentVariable('PATH')
$__PSProfileEnvTermProgram = [System.Environment]::GetEnvironmentVariable('TERM_PROGRAM')
$__PSProfileEnvAliasDirForce = [System.Environment]::GetEnvironmentVariable('PSPROFILE_ALIAS_DIR_FORCE')
$__PSProfileEnvAliasDirHidden = [System.Environment]::GetEnvironmentVariable('PSPROFILE_ALIAS_DIR_HIDDEN')
$__PSProfileEnvAliasDirSort = [System.Environment]::GetEnvironmentVariable('PSPROFILE_ALIAS_DIR_SORT')
if ($null -eq $__PSProfileEnvAliasDirForce) { $__PSProfileEnvAliasDirForce = $false; [System.Environment]::SetEnvironmentVariable('PSPROFILE_ALIAS_DIR_FORCE', $__PSProfileEnvAliasDirForce) }
if ($null -eq $__PSProfileEnvAliasDirHidden) { $__PSProfileEnvAliasDirHidden = $true; [System.Environment]::SetEnvironmentVariable('PSPROFILE_ALIAS_DIR_HIDDEN', $__PSProfileEnvAliasDirHidden) }
if ($null -eq $__PSProfileEnvAliasDirSort) { $__PSProfileEnvAliasDirSort = $true; [System.Environment]::SetEnvironmentVariable('PSPROFILE_ALIAS_DIR_SORT', $__PSProfileEnvAliasDirSort) }
#endregion Script Variables ----------------------------------------------------
# Display optional first run image specific notice if configured and terminal is interactive
if (
(__PSProfile-Assert-IsUserInteractiveShell) -and
$__PSProfileEnvTermProgram -match '^(vscode|codespaces)$' -and
-not ([System.IO.File]::Exists("${HOME}/.config/vscode-dev-containers/first-run-notice-already-displayed"))
) {
if ([System.IO.File]::Exists('/usr/local/etc/vscode-dev-containers/first-run-notice.txt')) {
[System.Console]::WriteLine(
(__PSProfile-Replace-EscapeSequences ([System.IO.File]::ReadAllText('/usr/local/etc/vscode-dev-containers/first-run-notice.txt')))
)
}
elseif ([System.IO.File]::Exists('/workspaces/.codespaces/shared/first-run-notice.txt')) {
[System.Console]::WriteLine(
(__PSProfile-Replace-EscapeSequences ([System.IO.File]::ReadAllText('/workspaces/.codespaces/shared/first-run-notice.txt')))
)
}
# Mark first run notice as displayed after 10s to avoid problems with fast terminal refreshes hiding it
$null = Start-ThreadJob -Name FirstRunNoticeAlreadyDisplayed -ScriptBlock {
Start-Sleep -Seconds 10
$null = New-Item -ItemType Directory -Force -Path "${HOME}/.config/vscode-dev-containers"
$null = New-Item -ItemType File -Force -Path "${HOME}/.config/vscode-dev-containers/first-run-notice-already-displayed"
}
}
__PSProfile-Write-ProfileLoadMessage "🌐 Loading $($PSStyle.Bold)system$($PSStyle.BoldOff) profile."
#region Global Variables =======================================================
$Global:___PSProfileSource = 'DevContainer-Feature:PowerShell-Extended'
#endregion Global Variables ----------------------------------------------------
#region Environment Variables ==================================================
# Add local bin directory to PATH if not already present
if ($__PSProfileEnvPathOriginal.Split(':') -notcontains "${HOME}/bin") { [System.Environment]::SetEnvironmentVariable('PATH', "$([System.Environment]::GetEnvironmentVariable('PATH')):${HOME}/bin") }
if ($__PSProfileEnvPathOriginal.Split(':') -notcontains "${HOME}/.local/bin") { [System.Environment]::SetEnvironmentVariable('PATH', "$([System.Environment]::GetEnvironmentVariable('PATH')):${HOME}/.local/bin") }
if ($__PSProfileEnvPathOriginal.Split(':') -notcontains "${HOME}/.local/share/powershell/Scripts") { [System.Environment]::SetEnvironmentVariable('PATH', "$([System.Environment]::GetEnvironmentVariable('PATH')):${HOME}/.local/share/powershell/Scripts") }
# Set the USER environment variable if not already set
if ($null -eq [System.Environment]::GetEnvironmentVariable('USER') -and $null -eq [System.Environment]::GetEnvironmentVariable('USERNAME')) { [System.Environment]::SetEnvironmentVariable('USER', (/usr/bin/whoami)) }
# Set the default git editor if not already set
if (
(__PSProfile-Assert-IsUserInteractiveShell) -and
$null -eq [System.Environment]::GetEnvironmentVariable('GIT_EDITOR') -and
$null -eq $(try { git config --get core.editor } catch { $Error.Clear(); $null })
) {
# Check if the terminal program is vscode
if ($__PSProfileEnvTermProgram -match '^(vscode|codespaces)$') {
# Check if code-insiders is available and code is not available
if ((Get-Command -Name 'code-insiders' -ErrorAction Ignore) -and $null -eq (Get-Command -Name 'code' -ErrorAction Ignore)) {
[System.Environment]::SetEnvironmentVariable('GIT_EDITOR', 'code-insiders --wait')
}
else {
[System.Environment]::SetEnvironmentVariable('GIT_EDITOR', 'code --wait')
}
}
}
#endregion Environment Variables -----------------------------------------------
#region Aliases ================================================================
if (
(__PSProfile-Assert-IsUserInteractiveShell) -and
(
$__PSProfileEnvAliasDirForce -eq $true -or
$__PSProfileEnvAliasDirHidden -eq $true -or
$__PSProfileEnvAliasDirSort -eq $true
)
) {
<#
This is a copy of:
CommandType Name Version Source
----------- ---- ------- ------
Cmdlet Get-ChildItem 7.0.0.0 Microsoft.PowerShell.Management
Created: 2024-08-11
Author : Julian Pawlowski
Created with PSScriptTools: Copy-Command Get-Childitem -AsProxy -UseForwardHelp -IncludeDynamic
#>
function ___PSProfileAliasDir {
<#
.ForwardHelpTargetName Microsoft.PowerShell.Management\Get-ChildItem
.ForwardHelpCategory Cmdlet
#>
[CmdletBinding(DefaultParameterSetName = 'Items', HelpUri = 'https://go.microsoft.com/fwlink/?LinkID=2096492')]
Param(
[Parameter(ParameterSetName = 'Items', Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[string[]]
${Path},
[Parameter(ParameterSetName = 'LiteralItems', Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[Alias('PSPath', 'LP')]
[string[]]
${LiteralPath},
[Parameter(Position = 1)]
[string]
${Filter},
[string[]]
${Include},
[string[]]
${Exclude},
[Alias('s')]
[switch]
${Recurse},
[uint]
${Depth},
[switch]
${Force},
[switch]
${Name},
[System.Management.Automation.FlagsExpression[System.IO.FileAttributes]]
${Attributes},
[switch]
${FollowSymlink},
[Alias('ad')]
[switch]
${Directory},
[Alias('af')]
[switch]
${File},
[Alias('ah', 'h')]
[switch]
${Hidden},
[Alias('ar')]
[switch]
${ReadOnly},
[Alias('as')]
[switch]
${System}
)
Begin {
Write-Verbose "[BEGIN ] Starting $($MyInvocation.MyCommand)"
Write-Verbose "[BEGIN ] Using parameter set $($PSCmdlet.ParameterSetName)"
try {
$outBuffer = $null
if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) {
$PSBoundParameters['OutBuffer'] = 1
}
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_ALIAS_DIR_FORCE') -eq $true) {
$PSBoundParameters['Force'] = $true
}
elseif ([System.Environment]::GetEnvironmentVariable('PSPROFILE_ALIAS_DIR_HIDDEN') -eq $true) {
$PSBoundParameters['Hidden'] = $true
}
Write-Verbose ($PSBoundParameters | Out-String)
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Management\Get-ChildItem', [System.Management.Automation.CommandTypes]::Cmdlet)
if ([System.Environment]::GetEnvironmentVariable('PSPROFILE_ALIAS_DIR_SORT') -eq $true) {
Write-Verbose 'Sorting by container status and name'
$scriptCmd = { & $wrappedCmd @PSBoundParameters | Sort-Object -Property { -not $_.psiscontainer }, Name }
}
else {
$scriptCmd = { & $wrappedCmd @PSBoundParameters }
}
$steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin)
$steppablePipeline.Begin($PSCmdlet)
}
catch { throw }
}
Process {
try { $steppablePipeline.Process($_) } catch { throw }
}
End {
Write-Verbose "[END ] Ending $($MyInvocation.MyCommand)"
try { $steppablePipeline.End() } catch { throw }
}
}
New-Alias -Name dir -Value ___PSProfileAliasDir -Option AllScope -Force
}
#endregion Import Modules ------------------------------------------------------
#region Custom Profile =========================================================
#
# Hint:
# To load your own custom profile, you may create a directory named 'profile.d' in the same directory as this file.
# Then, place your custom profile files in the '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 {
$__PSProfileError = "`n❌ Interrupting profile load process.`n"
if (Get-Command -Name '__PSProfile-Write-ProfileLoadMessage' -ErrorAction Ignore) { __PSProfile-Write-ProfileLoadMessage $__PSProfileError -ForegroundColor DarkRed } else { Write-Host $__PSProfileError -ForegroundColor DarkRed }
Write-Error "An error occurred while loading the global profile." -ErrorAction Continue
throw
}
finally {
if (Get-Command -Name '__PSProfile-Clear-Environment' -ErrorAction Ignore) { __PSProfile-Clear-Environment }
}