From 4160e972b4feefc6919937d31ba34cfa73cf315f Mon Sep 17 00:00:00 2001 From: Jimmy Briggs Date: Wed, 17 Jan 2024 19:32:11 -0500 Subject: [PATCH] feat: add PSProfile.Prompt.ps1 for #16 --- PSProfile/PSProfile.Prompt.ps1 | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 PSProfile/PSProfile.Prompt.ps1 diff --git a/PSProfile/PSProfile.Prompt.ps1 b/PSProfile/PSProfile.Prompt.ps1 new file mode 100644 index 0000000..9da0cc1 --- /dev/null +++ b/PSProfile/PSProfile.Prompt.ps1 @@ -0,0 +1,37 @@ +# ----------------------------------------------------------------------------- +# PowerShell Profile - Prompt +# ----------------------------------------------------------------------------- + +Class OMPThemes : System.Management.Automation.IValidateSetValuesGenerator { + [String[]] GetValidValues() { + $OMPThemes = ((Get-ChildItem -Path "$Env:POSH_THEMES_PATH" -Filter "*.omp.json").Name -replace ".omp.json", "") + return [String[]]$OMPThemes + } +} + +Function Set-OMPTheme { + [CmdletBinding()] + Param( + [ValidateSet([OMPThemes])] + [String]$Theme + ) + + try { + $ConfigPath = Join-Path "$Env:POSH_THEMES_PATH" "$Theme.omp.json" + (& oh-my-posh init pwsh --config=$ConfigPath --print) -join "`n" | Invoke-Expression + } catch [CommandNotFoundException] { + Write-Warning "Failed to set oh-my-posh theme" + return + } finally { + if ($?) { + Write-Verbose "oh-my-posh theme set to '$Theme'" + $Global:POSH_THEME = $Theme + } + } + +} + +if (Get-Command oh-my-posh -ErrorAction SilentlyContinue) { + Write-Verbose "Setting oh-my-posh theme..." + Set-OMPTheme -Theme space +}