Mastodon

Customizing Windows Terminal with Oh my Posh 3

Mar 12, 2021 by Kolappan N

Oh my Posh is an excellent tool to customize your Windows Terminal. I started customizing my Windows Terminal with Oh my Posh 2 and Posh git based on an excellent blog post by Scott Hanselman. However with the release of Oh my Posh 3 a lot has changed & the old workflow is no longer working. Oh my Posh 3 brings a lot to the table & removes the dependency on Posh git. Here is how I customized the Terminal with oh my posh 3.

Setup

  1. Install the Windows Terminal from Windows Store.
  2. Install a font with PowerLine support. In this setup I use Cascadia Code PL. The PL stands for PowerLine and is different form the regular font with support for additional characters.
  3. Install Oh my Posh 3 using the following command
    Install-Module oh-my-posh -Scope CurrentUser -AllowPrerelease
    
  4. Now you set a Theme for you oh my posh. There are some prebuilt themes available. To use a prebuilt theme, add the following code to your PowerShell $PROFILE.
    Set-PoshPrompt -Theme theme_name
    

Note: If you have Windows PowerShell & PowerShell Core and you want to setup Oh my Posh on both of them, you need to repeat steps 3 & 4 on them separately.

Customization

Oh my Posh 3 offers powerful customizations. The entire powerline you see in the Windows Terminal is split into segments. You can turn off individual segments on & off. Each segment also provide its own set of options to customize it further. If that is not enough for you then you can create your own segment with go language.

My Windows Terminal
My Windows Terminal

In the above image, you can see that my powerline is comprised of three segments - Path, Git status & Node js. The full list of prebuilt segments can be seen at oh my posh’s website. The segments are displayed conditionally. For example, the Node js version is displayed only when a JavaScript or package.json file is located. Similarly the git status is displayed only when you are in a local git repo.

To customize and choose your segment you’ll need to create a new omp.json file and set it as the theme. My theme json file looks like the following,

{
    "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
    "blocks": [
        {
            "type": "prompt",
            "alignment": "left",
            "segments": [
                {
                    "type": "path",
                    "style": "powerline",
                    "powerline_symbol": "\uE0B0",
                    "foreground": "#FBEAEB",
                    "background": "#2F3C7E",
                    "properties": {
                        "style": "full"
                    }
                },
                {
                    "type": "git",
                    "style": "powerline",
                    "powerline_symbol": "\uE0B0",
                    "foreground": "#292826",
                    "background": "#F9D342",
                    "properties": {
                        "local_working_icon": " *",
                        "local_staged_icon": " ⇡",
                        "status_colors_enabled": true
                    }
                },
                {
                    "type": "dotnet",
                    "style": "powerline",
                    "powerline_symbol": "",
                    "foreground": "#FBEAEB",
                    "background": "#EC4D37",
                    "properties": {
                        "prefix": ".NET "
                    }
                },
                {
                    "type": "node",
                    "style": "powerline",
                    "powerline_symbol": "\uE0B0",
                    "foreground": "#FBEAEB",
                    "background": "#EC4D37",
                    "properties": {
                        "prefix": "node "
                    }
                }
            ]
        }
    ],
    "final_space": true
}

The two character changes you see for the git segment are needed if you are using Cascadia Code PL. At the time of writing this font doesn’t have the default characters so I replaced them in json. The local_working_icon is displayed when there is an uncommitted change in the git repo. Also remember to set your json file as the default theme in your PowerShell $PROFILE

Set-PoshPrompt -Theme C:\my-theme.omp.json