Skip to content

Commit

Permalink
feat: -list parameter added to Get-PoshThemes
Browse files Browse the repository at this point in the history
-list display the theme full path instead of the preview
Themes location added at the end
  • Loading branch information
lnu authored and JanDeDobbeleer committed Jun 5, 2021
1 parent 930f9de commit abe3d09
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/docs/install-pwsh.mdx
Expand Up @@ -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
Expand Down
41 changes: 31 additions & 10 deletions packages/powershell/oh-my-posh/oh-my-posh.psm1
Expand Up @@ -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 = @'
Expand All @@ -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 ""
Expand Down Expand Up @@ -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()); } |
Expand Down

0 comments on commit abe3d09

Please sign in to comment.