diff --git a/functions/private/Invoke-WinUtilInstallPSProfile.ps1 b/functions/private/Invoke-WinUtilInstallPSProfile.ps1 index 4fc8caaa..77dce2c9 100644 --- a/functions/private/Invoke-WinUtilInstallPSProfile.ps1 +++ b/functions/private/Invoke-WinUtilInstallPSProfile.ps1 @@ -16,9 +16,17 @@ function Invoke-WinUtilInstallPSProfile { } if ($NewHash.Hash -ne $OldHash.Hash) { - if ((Test-Path $PSProfile) -and (-not (Test-Path "$PSProfile.bak"))) { - Write-Host "===> Backing Up Profile... <===" -ForegroundColor Yellow - Copy-Item -Path $PSProfile -Destination "$PSProfile.bak" + if (Test-Path "$env:USERPROFILE\oldprofile.ps1") { + Write-Host "===> Backup File Exists... <===" -ForegroundColor Yellow + Write-Host "===> Moving Backup File... <===" -ForegroundColor Yellow + Copy-Item "$env:USERPROFILE\oldprofile.ps1" "$PSProfile.bak" + Write-Host "===> Profile Backup: Done. <===" -ForegroundColor Yellow + } else { + if ((Test-Path $PSProfile) -and (-not (Test-Path "$PSProfile.bak"))) { + Write-Host "===> Backing Up Profile... <===" -ForegroundColor Yellow + Copy-Item -Path $PSProfile -Destination "$PSProfile.bak" + Write-Host "===> Profile Backup: Done. <===" -ForegroundColor Yellow + } } Write-Host "===> Installing Profile... <===" -ForegroundColor Yellow diff --git a/functions/private/Invoke-WinUtilUninstallPSProfile.ps1 b/functions/private/Invoke-WinUtilUninstallPSProfile.ps1 index 2d5d5f77..ffc91236 100644 --- a/functions/private/Invoke-WinUtilUninstallPSProfile.ps1 +++ b/functions/private/Invoke-WinUtilUninstallPSProfile.ps1 @@ -5,7 +5,6 @@ function Invoke-WinUtilUninstallPSProfile { #> Invoke-WPFRunspace -ArgumentList $PROFILE -DebugPreference $DebugPreference -ScriptBlock { - # PSProfile parameter param ($PSProfile) # Function to uninstall Nerd Fonts @@ -33,10 +32,7 @@ function Invoke-WinUtilUninstallPSProfile { if ((Get-FileHash $PSProfile).Hash -eq $PSProfileHash) { # Uninstall OhMyPosh try { - # Get backup profile's content $PSProfileContent = Get-Content "$PSProfile.bak" - - # Check if OhMyPosh is in use $OhMyPoshInUse = $PSProfileContent -match "oh-my-posh init" if (-not $OhMyPoshInUse) { if (Get-Command oh-my-posh -ErrorAction SilentlyContinue) { @@ -61,10 +57,7 @@ function Invoke-WinUtilUninstallPSProfile { # Uninstall Terminal-Icons try { - # Get backup profile's content $PSProfileContent = Get-Content "$PSProfile.bak" - - # Check if Terminal-Icons is in use $TerminalIconsInUse = $PSProfileContent -match "Import-Module" -and $PSProfileContent -match "Terminal-Icons" if (-not $TerminalIconsInUse) { if (Get-Module -ListAvailable Terminal-Icons) { @@ -80,10 +73,7 @@ function Invoke-WinUtilUninstallPSProfile { # Uninstall Zoxide try { - # Get backup profile's content $PSProfileContent = Get-Content "$PSProfile.bak" - - # Check if Zoxide is in use $ZoxideInUse = $PSProfileContent -match "zoxide init" if (-not $ZoxideInUse) { if (Get-Command zoxide -ErrorAction SilentlyContinue) { @@ -115,6 +105,9 @@ function Invoke-WinUtilUninstallPSProfile { Write-Error "Failed to restore profile backup. Error: $_" -ForegroundColor Red } + # Silently cleanup oldprofile.ps1 script + Remove-Item "$env:USERPROFILE\oldprofile.ps1" | Out-Null + # Silently cleanup $PSProfile.hash file Remove-Item "$PSProfile.hash" | Out-Null } else {