From e68be7aa44fb00bc5d81a839f818bd077bc5a1a9 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Sat, 28 Nov 2020 11:03:41 +0100 Subject: [PATCH] feat: use *.omp.json as theme format --- docs/docs/installation.mdx | 37 ++++++++++++++----- .../powershell/oh-my-posh/oh-my-posh.psm1 | 10 ++--- themes/{agnoster.json => agnoster.omp.json} | 0 ...gnosterplus.json => agnosterplus.omp.json} | 0 themes/{aliens.json => aliens.omp.json} | 0 themes/{avit.json => avit.omp.json} | 0 themes/{darkblood.json => darkblood.omp.json} | 0 themes/{emodipt.json => emodipt.omp.json} | 0 themes/{fish.json => fish.omp.json} | 0 themes/{honukai.json => honukai.omp.json} | 0 ...dobbeleer.json => jandedobbeleer.omp.json} | 0 themes/{lambda.json => lambda.omp.json} | 0 themes/{material.json => material.omp.json} | 0 themes/{paradox.json => paradox.omp.json} | 0 .../{pararussel.json => pararussel.omp.json} | 0 ...ic.json => powerlevel10k_classic.omp.json} | 0 ..._lean.json => powerlevel10k_lean.omp.json} | 0 themes/{powerline.json => powerline.omp.json} | 0 ...{robbyrussel.json => robbyrussel.omp.json} | 0 themes/{sorin.json => sorin.omp.json} | 0 themes/{star.json => star.omp.json} | 0 themes/{zash.json => zash.omp.json} | 0 22 files changed, 32 insertions(+), 15 deletions(-) rename themes/{agnoster.json => agnoster.omp.json} (100%) rename themes/{agnosterplus.json => agnosterplus.omp.json} (100%) rename themes/{aliens.json => aliens.omp.json} (100%) rename themes/{avit.json => avit.omp.json} (100%) rename themes/{darkblood.json => darkblood.omp.json} (100%) rename themes/{emodipt.json => emodipt.omp.json} (100%) rename themes/{fish.json => fish.omp.json} (100%) rename themes/{honukai.json => honukai.omp.json} (100%) rename themes/{jandedobbeleer.json => jandedobbeleer.omp.json} (100%) rename themes/{lambda.json => lambda.omp.json} (100%) rename themes/{material.json => material.omp.json} (100%) rename themes/{paradox.json => paradox.omp.json} (100%) rename themes/{pararussel.json => pararussel.omp.json} (100%) rename themes/{powerlevel10k_classic.json => powerlevel10k_classic.omp.json} (100%) rename themes/{powerlevel10k_lean.json => powerlevel10k_lean.omp.json} (100%) rename themes/{powerline.json => powerline.omp.json} (100%) rename themes/{robbyrussel.json => robbyrussel.omp.json} (100%) rename themes/{sorin.json => sorin.omp.json} (100%) rename themes/{star.json => star.omp.json} (100%) rename themes/{zash.json => zash.omp.json} (100%) diff --git a/docs/docs/installation.mdx b/docs/docs/installation.mdx index bab77d39..e428e144 100644 --- a/docs/docs/installation.mdx +++ b/docs/docs/installation.mdx @@ -205,7 +205,7 @@ Edit `$PROFILE` in your preferred PowerShell version and add the following lines $startInfo = New-Object System.Diagnostics.ProcessStartInfo $startInfo.FileName = "C:\tools\oh-my-posh.exe" $cleanPWD = $PWD.ProviderPath.TrimEnd("\") - $startInfo.Arguments = "-config=""$env:USERPROFILE\.poshthemes\jandedobbeleer.json"" -error=$errorCode -pwd=""$cleanPWD""" + $startInfo.Arguments = "-config=""$env:USERPROFILE\.poshthemes\jandedobbeleer.omp.json"" -error=$errorCode -pwd=""$cleanPWD""" $startInfo.Environment["TERM"] = "xterm-256color" $startInfo.CreateNoWindow = $true $startInfo.StandardOutputEncoding = [System.Text.Encoding]::UTF8 @@ -241,7 +241,7 @@ Add the following to `~/.zshrc`: ```bash function powerline_precmd() { - PS1="$(oh-my-posh -config ~/.poshthemes/jandedobbeleer.json --error $?)" + PS1="$(oh-my-posh -config ~/.poshthemes/jandedobbeleer.omp.json --error $?)" } function install_powerline_precmd() { @@ -271,7 +271,7 @@ Add the following to `~/.bashrc` (or `~/.profile` on MacOS): ```bash function _update_ps1() { - PS1="$(oh-my-posh -config ~/.poshthemes/jandedobbeleer.json -error $?)" + PS1="$(oh-my-posh -config ~/.poshthemes/jandedobbeleer.omp.json -error $?)" } if [ "$TERM" != "linux" ] && [ -x "$(command -v oh-my-posh)" ]; then @@ -304,7 +304,7 @@ which should re-enable the prompt in most cases: # Workaround for nix-shell --pure if [ "$IN_NIX_SHELL" == "pure" ]; then if [ -x oh-my-posh ]; then - alias powerline-go="oh-my-posh -config ~/.poshthemes/jandedobbeleer.json" + alias powerline-go="oh-my-posh -config ~/.poshthemes/jandedobbeleer.omp.json" fi fi ``` @@ -322,7 +322,7 @@ Redefine `fish_prompt` in `~/.config/fish/config.fish`: ```bash function fish_prompt - eval oh-my-posh -config ~/.poshthemes/jandedobbeleer.json -error $status + eval oh-my-posh -config ~/.poshthemes/jandedobbeleer.omp.json -error $status end ``` @@ -338,7 +338,7 @@ Once added, reload your config for the changes to take effect. Set the prompt and restart nu shell: ```bash -config set prompt "= `{{$(oh-my-posh -config ~/.poshthemes/jandedobbeleer.json | str collect)}}`" +config set prompt "= `{{$(oh-my-posh -config ~/.poshthemes/jandedobbeleer.omp.json | str collect)}}`" ``` Restart nu shell for the changes to take effect. @@ -348,13 +348,13 @@ Restart nu shell for the changes to take effect. ### 5. Next steps -At this point you're good to go. The `jandedobbeleer.json` theme displays most common use-cases +At this point you're good to go. The `jandedobbeleer.omp.json` theme displays most common use-cases in your prompt so 9/10 you'll be more than happy with it. However, if you want to explore additional functionality, going through the additional steps below will help you get started. #### Change the theme -We downloaded all the themes and set `jandedobbeleer.json` as the one to use. +We downloaded all the themes and set `jandedobbeleer.omp.json` as the one to use. However, there are a lot more to be discovered and maybe there are some you like better. Adjust your configuration to use any other theme from the folder we created (`~/.poshthemes`). @@ -365,7 +365,7 @@ Maybe there's a theme you like, but you don't fancy the colors. Or, maybe there' want to tweak/add, or replace some of the icons with a different one. Whatever the case, read through all available options first, by starting with the [configuration guide][configuration]. -Afterwards, the easiest way to go about this is to print the current config and store it elsewhere first (for example `~/.mytheme.json`). +Afterwards, the easiest way to go about this is to print the current config and store it elsewhere first (for example `~/.mytheme.omp.json`). ```bash oh-my-posh --print-config @@ -375,7 +375,22 @@ This will write the current configuration in your shell, allowing you to copy pa and store it somehwere. Once adjusted to your liking, [change the prompt setting][prompt] to use the newly created file. ```bash -oh-my-posh -config ~/.mytheme.json +oh-my-posh -config ~/.mytheme.omp.json +``` + +#### JSON Schema + +There's an easy to use [JSON schema][schema] available to validate your theme and have auto completion when editing. +When using [Visual Studio Code][vscode], you can extend your settings file (F1 -> Preferences: Open Settings (JSON)) +by adding the following lines: + +```json +"json.schemas": [ + { + "fileMatch": ["*.omp.json"], + "url": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh3/main/themes/schema.json" + } +] ``` 🎉🎉🎉 @@ -392,3 +407,5 @@ oh-my-posh -config ~/.mytheme.json [brew]: /docs/homebrew [prompt]: /docs/installation#4-replace-your-existing-prompt [configuration]: /docs/configure +[schema]: https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh3/main/themes/schema.json +[vscode]: https://code.visualstudio.com/ diff --git a/packages/powershell/oh-my-posh/oh-my-posh.psm1 b/packages/powershell/oh-my-posh/oh-my-posh.psm1 index d0b5fc80..46767d98 100644 --- a/packages/powershell/oh-my-posh/oh-my-posh.psm1 +++ b/packages/powershell/oh-my-posh/oh-my-posh.psm1 @@ -45,14 +45,14 @@ function Set-PoshPrompt { $global:PoshSettings.ShowDebug = $ShowDebug - if (Test-Path "$PSScriptRoot/themes/$Theme.json") { - $global:PoshSettings.Theme = "$PSScriptRoot/themes/$Theme.json" + if (Test-Path "$PSScriptRoot/themes/$Theme.omp.json") { + $global:PoshSettings.Theme = "$PSScriptRoot/themes/$Theme.omp.json" } elseif (Test-Path $Theme) { $global:PoshSettings.Theme = Resolve-Path -Path $Theme } else { - $global:PoshSettings.Theme = "$PSScriptRoot/themes/jandedobbeleer.json" + $global:PoshSettings.Theme = "$PSScriptRoot/themes/jandedobbeleer.omp.json" } [ScriptBlock]$Prompt = { @@ -115,7 +115,7 @@ function Get-PoshThemes { '@ Write-Host $logo $poshCommand = Get-PoshCommand - Get-ChildItem -Path "$PSScriptRoot\themes\*" -Include '*.json' | Sort-Object Name | ForEach-Object -Process { + Get-ChildItem -Path "$PSScriptRoot\themes\*" -Include '*.omp.json' | Sort-Object Name | ForEach-Object -Process { Write-Host ("=" * $consoleWidth) Write-Host "$esc[1m$($_.BaseName)$esc[0m" Write-Host "" @@ -152,7 +152,7 @@ function ThemeCompletion { $commandAst, $fakeBoundParameter ) - $themes = Get-ChildItem -Path "$PSScriptRoot\themes\*" -Include '*.json' | Sort-Object Name | Select-Object -Property BaseName + $themes = Get-ChildItem -Path "$PSScriptRoot\themes\*" -Include '*.omp.json' | Sort-Object Name | Select-Object -Property BaseName $themes | Where-Object { $_.BaseName.ToLower().StartsWith($wordToComplete.ToLower()); } | Select-Object -Unique -ExpandProperty BaseName | diff --git a/themes/agnoster.json b/themes/agnoster.omp.json similarity index 100% rename from themes/agnoster.json rename to themes/agnoster.omp.json diff --git a/themes/agnosterplus.json b/themes/agnosterplus.omp.json similarity index 100% rename from themes/agnosterplus.json rename to themes/agnosterplus.omp.json diff --git a/themes/aliens.json b/themes/aliens.omp.json similarity index 100% rename from themes/aliens.json rename to themes/aliens.omp.json diff --git a/themes/avit.json b/themes/avit.omp.json similarity index 100% rename from themes/avit.json rename to themes/avit.omp.json diff --git a/themes/darkblood.json b/themes/darkblood.omp.json similarity index 100% rename from themes/darkblood.json rename to themes/darkblood.omp.json diff --git a/themes/emodipt.json b/themes/emodipt.omp.json similarity index 100% rename from themes/emodipt.json rename to themes/emodipt.omp.json diff --git a/themes/fish.json b/themes/fish.omp.json similarity index 100% rename from themes/fish.json rename to themes/fish.omp.json diff --git a/themes/honukai.json b/themes/honukai.omp.json similarity index 100% rename from themes/honukai.json rename to themes/honukai.omp.json diff --git a/themes/jandedobbeleer.json b/themes/jandedobbeleer.omp.json similarity index 100% rename from themes/jandedobbeleer.json rename to themes/jandedobbeleer.omp.json diff --git a/themes/lambda.json b/themes/lambda.omp.json similarity index 100% rename from themes/lambda.json rename to themes/lambda.omp.json diff --git a/themes/material.json b/themes/material.omp.json similarity index 100% rename from themes/material.json rename to themes/material.omp.json diff --git a/themes/paradox.json b/themes/paradox.omp.json similarity index 100% rename from themes/paradox.json rename to themes/paradox.omp.json diff --git a/themes/pararussel.json b/themes/pararussel.omp.json similarity index 100% rename from themes/pararussel.json rename to themes/pararussel.omp.json diff --git a/themes/powerlevel10k_classic.json b/themes/powerlevel10k_classic.omp.json similarity index 100% rename from themes/powerlevel10k_classic.json rename to themes/powerlevel10k_classic.omp.json diff --git a/themes/powerlevel10k_lean.json b/themes/powerlevel10k_lean.omp.json similarity index 100% rename from themes/powerlevel10k_lean.json rename to themes/powerlevel10k_lean.omp.json diff --git a/themes/powerline.json b/themes/powerline.omp.json similarity index 100% rename from themes/powerline.json rename to themes/powerline.omp.json diff --git a/themes/robbyrussel.json b/themes/robbyrussel.omp.json similarity index 100% rename from themes/robbyrussel.json rename to themes/robbyrussel.omp.json diff --git a/themes/sorin.json b/themes/sorin.omp.json similarity index 100% rename from themes/sorin.json rename to themes/sorin.omp.json diff --git a/themes/star.json b/themes/star.omp.json similarity index 100% rename from themes/star.json rename to themes/star.omp.json diff --git a/themes/zash.json b/themes/zash.omp.json similarity index 100% rename from themes/zash.json rename to themes/zash.omp.json