-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
for #16
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |