From 2300d05c871925abb474e6457d196e5e793c3edd Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Thu, 27 Jul 2023 01:55:44 +0200 Subject: [PATCH] Allow the addition of custom PowerShell profiles --- scripts/Windows/Scripts/Context.ps1 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/scripts/Windows/Scripts/Context.ps1 b/scripts/Windows/Scripts/Context.ps1 index 719c82f5..aea7307e 100644 --- a/scripts/Windows/Scripts/Context.ps1 +++ b/scripts/Windows/Scripts/Context.ps1 @@ -34,6 +34,22 @@ class Context { Get-PinnedItem -Type TaskBar | Where-Object { $_.Name -like "$pattern" } | Remove-PinnedItem; } + [void] AddPowerShellProfileStatement([string] $statement) { + $this.AddPowerShellProfileStatement($null, $statement); + } + + [void] AddPowerShellProfileStatement([string] $category, [string] $statement) { + Push-Location ~; + $profileFiles = @((powershell -c '$PROFILE'), (pwsh -c '$PROFILE')) | ForEach-Object { Resolve-Path -Relative $_ }; + + if ($category) { + $profileFiles = $profileFiles | ForEach-Object { Join-Path (Split-Path -Parent $_) "profile.d" "$category.ps1"; }; + } + + $profileFiles | ForEach-Object { Add-Content "C:\Users\Default\$_" "`n$statement"; }; + Pop-Location; + } + [Microsoft.Win32.RegistryKey] EnsureConfigKey() { if (-not (Test-Path $this.ConfigRoot)) { $null = New-Item $this.ConfigRoot;