Skip to content

Commit 4160e97

Browse files
committed
feat: add PSProfile.Prompt.ps1
for #16
1 parent d4d77b4 commit 4160e97

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

PSProfile/PSProfile.Prompt.ps1

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# -----------------------------------------------------------------------------
2+
# PowerShell Profile - Prompt
3+
# -----------------------------------------------------------------------------
4+
5+
Class OMPThemes : System.Management.Automation.IValidateSetValuesGenerator {
6+
[String[]] GetValidValues() {
7+
$OMPThemes = ((Get-ChildItem -Path "$Env:POSH_THEMES_PATH" -Filter "*.omp.json").Name -replace ".omp.json", "")
8+
return [String[]]$OMPThemes
9+
}
10+
}
11+
12+
Function Set-OMPTheme {
13+
[CmdletBinding()]
14+
Param(
15+
[ValidateSet([OMPThemes])]
16+
[String]$Theme
17+
)
18+
19+
try {
20+
$ConfigPath = Join-Path "$Env:POSH_THEMES_PATH" "$Theme.omp.json"
21+
(& oh-my-posh init pwsh --config=$ConfigPath --print) -join "`n" | Invoke-Expression
22+
} catch [CommandNotFoundException] {
23+
Write-Warning "Failed to set oh-my-posh theme"
24+
return
25+
} finally {
26+
if ($?) {
27+
Write-Verbose "oh-my-posh theme set to '$Theme'"
28+
$Global:POSH_THEME = $Theme
29+
}
30+
}
31+
32+
}
33+
34+
if (Get-Command oh-my-posh -ErrorAction SilentlyContinue) {
35+
Write-Verbose "Setting oh-my-posh theme..."
36+
Set-OMPTheme -Theme space
37+
}

0 commit comments

Comments
 (0)