feat: -list parameter added to Get-PoshThemes

-list display the theme full path instead of the preview
Themes location added at the end
This commit is contained in:
lnu 2021-06-05 14:08:45 +02:00 committed by Jan De Dobbeleer
parent 930f9de114
commit abe3d0990b
2 changed files with 32 additions and 11 deletions

View file

@ -42,7 +42,7 @@ Get-PoshThemes
The module installs all themes in the module folder. To find the actual files, you can use the following command: The module installs all themes in the module folder. To find the actual files, you can use the following command:
```powershell ```powershell
Get-ChildItem "$((Get-Module oh-my-posh).ModuleBase)/themes" Get-PoshThemes -list
``` ```
## Replace your existing prompt ## Replace your existing prompt

View file

@ -70,7 +70,20 @@ function Set-PoshPrompt {
(& $poshCommand --init --shell=pwsh --config="$config") | Invoke-Expression (& $poshCommand --init --shell=pwsh --config="$config") | Invoke-Expression
} }
function Get-PoshThemes { <#
.SYNOPSIS
Display a preview or a list of installed themes.
.EXAMPLE
Get-PoshThemes
.Example
Gest-PoshThemes -list
#>
function Get-PoshThemes() {
param(
[switch]
[Parameter(Mandatory = $false, HelpMessage = "List themes path")]
$list
)
$esc = [char]27 $esc = [char]27
$consoleWidth = $Host.UI.RawUI.WindowSize.Width $consoleWidth = $Host.UI.RawUI.WindowSize.Width
$logo = @' $logo = @'
@ -84,16 +97,24 @@ function Get-PoshThemes {
|___/ |___/
'@ '@
Write-Host $logo Write-Host $logo
$poshCommand = Get-PoshCommand $themes = Get-ChildItem -Path "$PSScriptRoot\themes\*" -Include '*.omp.json' | Sort-Object Name
Get-ChildItem -Path "$PSScriptRoot\themes\*" -Include '*.omp.json' | Sort-Object Name | ForEach-Object -Process {
Write-Host ("-" * $consoleWidth) Write-Host ("-" * $consoleWidth)
if ($list -eq $true) {
$themes | Select-Object fullname | Format-Table -HideTableHeaders
}
else {
$poshCommand = Get-PoshCommand
$themes | ForEach-Object -Process {
Write-Host "Theme: $esc[1m$($_.BaseName.Replace('.omp', ''))$esc[0m" Write-Host "Theme: $esc[1m$($_.BaseName.Replace('.omp', ''))$esc[0m"
Write-Host "" Write-Host ""
& $poshCommand -config $($_.FullName) -pwd $PWD & $poshCommand -config $($_.FullName) -pwd $PWD
Write-Host "" Write-Host ""
} }
}
Write-Host ("-" * $consoleWidth) Write-Host ("-" * $consoleWidth)
Write-Host "" Write-Host ""
Write-Host "Themes location: $PSScriptRoot\themes"
Write-Host ""
Write-Host "To change your theme, use the Set-PoshPrompt command. Example:" Write-Host "To change your theme, use the Set-PoshPrompt command. Example:"
Write-Host " Set-PoshPrompt -Theme jandedobbeleer" Write-Host " Set-PoshPrompt -Theme jandedobbeleer"
Write-Host "" Write-Host ""
@ -121,8 +142,8 @@ function ThemeCompletion {
$fakeBoundParameter $fakeBoundParameter
) )
$themes = Get-ChildItem -Path "$PSScriptRoot\themes\*" -Include '*.omp.json' | Sort-Object Name | Select-Object -Property @{ $themes = Get-ChildItem -Path "$PSScriptRoot\themes\*" -Include '*.omp.json' | Sort-Object Name | Select-Object -Property @{
label='BaseName' label = 'BaseName'
expression={$_.BaseName.Replace('.omp', '')} expression = { $_.BaseName.Replace('.omp', '') }
} }
$themes | $themes |
Where-Object { $_.BaseName.ToLower().StartsWith($wordToComplete.ToLower()); } | Where-Object { $_.BaseName.ToLower().StartsWith($wordToComplete.ToLower()); } |