From abe3d0990ba49752bd4876d4011a4d5d3e677886 Mon Sep 17 00:00:00 2001 From: lnu Date: Sat, 5 Jun 2021 14:08:45 +0200 Subject: [PATCH] feat: -list parameter added to Get-PoshThemes -list display the theme full path instead of the preview Themes location added at the end --- docs/docs/install-pwsh.mdx | 2 +- .../powershell/oh-my-posh/oh-my-posh.psm1 | 41 ++++++++++++++----- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/docs/docs/install-pwsh.mdx b/docs/docs/install-pwsh.mdx index c6b66d70c368..c35cf42bf80e 100644 --- a/docs/docs/install-pwsh.mdx +++ b/docs/docs/install-pwsh.mdx @@ -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: ```powershell -Get-ChildItem "$((Get-Module oh-my-posh).ModuleBase)/themes" +Get-PoshThemes -list ``` ## Replace your existing prompt diff --git a/packages/powershell/oh-my-posh/oh-my-posh.psm1 b/packages/powershell/oh-my-posh/oh-my-posh.psm1 index 3f4fb9974abb..3ec16868cf09 100644 --- a/packages/powershell/oh-my-posh/oh-my-posh.psm1 +++ b/packages/powershell/oh-my-posh/oh-my-posh.psm1 @@ -70,7 +70,20 @@ function Set-PoshPrompt { (& $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 $consoleWidth = $Host.UI.RawUI.WindowSize.Width $logo = @' @@ -84,16 +97,24 @@ function Get-PoshThemes { |___/ '@ Write-Host $logo - $poshCommand = Get-PoshCommand - Get-ChildItem -Path "$PSScriptRoot\themes\*" -Include '*.omp.json' | Sort-Object Name | ForEach-Object -Process { - Write-Host ("-" * $consoleWidth) - Write-Host "Theme: $esc[1m$($_.BaseName.Replace('.omp', ''))$esc[0m" - Write-Host "" - & $poshCommand -config $($_.FullName) -pwd $PWD - Write-Host "" + $themes = Get-ChildItem -Path "$PSScriptRoot\themes\*" -Include '*.omp.json' | Sort-Object Name + 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 "" + & $poshCommand -config $($_.FullName) -pwd $PWD + Write-Host "" + } } Write-Host ("-" * $consoleWidth) Write-Host "" + Write-Host "Themes location: $PSScriptRoot\themes" + Write-Host "" Write-Host "To change your theme, use the Set-PoshPrompt command. Example:" Write-Host " Set-PoshPrompt -Theme jandedobbeleer" Write-Host "" @@ -121,8 +142,8 @@ function ThemeCompletion { $fakeBoundParameter ) $themes = Get-ChildItem -Path "$PSScriptRoot\themes\*" -Include '*.omp.json' | Sort-Object Name | Select-Object -Property @{ - label='BaseName' - expression={$_.BaseName.Replace('.omp', '')} + label = 'BaseName' + expression = { $_.BaseName.Replace('.omp', '') } } $themes | Where-Object { $_.BaseName.ToLower().StartsWith($wordToComplete.ToLower()); } |