feat: lock when loading profile + improvements to terminal settings

This commit is contained in:
Stevan Freeborn
2026-07-21 16:23:48 -05:00
parent daaf89aa00
commit e8f8196fcc
2 changed files with 60 additions and 42 deletions
@@ -2,16 +2,32 @@ $CurrentDir = if ($PSScriptRoot) { $PSScriptRoot } else { Split-Path -Parent $PR
$ProfileDir = Join-Path -Path $CurrentDir -ChildPath "Profile"
if (Test-Path -Path $ProfileDir) {
$ProfileScripts = Get-ChildItem -Path $ProfileDir -Filter "*.ps1" | Sort-Object Name
foreach ($Script in $ProfileScripts) {
try {
. $Script.FullName
$mutexName = "Global\PowerShellProfileInit"
$mutex = [System.Threading.Mutex]::new($false, $mutexName)
$acquired = $false
try {
$acquired = $mutex.WaitOne(10000)
if ($acquired) {
$ProfileScripts = Get-ChildItem -Path $ProfileDir -Filter "*.ps1" | Sort-Object Name
foreach ($Script in $ProfileScripts) {
try {
. $Script.FullName
}
catch {
Write-Warning "Failed to load profile module: $($Script.Name). Error: $($_.Exception.Message)"
}
}
}
catch {
Write-Warning "Failed to load profile module: $($Script.Name). Error: $($_.Exception.Message)"
else {
Write-Warning "Profile initialization lock timed out — another terminal may be loading."
}
}
} else {
finally {
if ($acquired) { $mutex.ReleaseMutex() }
$mutex.Dispose()
}
}
else {
Write-Warning "Profile directory not found at: $ProfileDir"
}