Skip to content

Commit

Permalink
feat: add PSProfile.Prompt.ps1
Browse files Browse the repository at this point in the history
for #16
  • Loading branch information
jimbrig committed Jan 18, 2024
1 parent d4d77b4 commit 4160e97
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions PSProfile/PSProfile.Prompt.ps1
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 4160e97

Please sign in to comment.