Altijd in beweging...

Technische ontwikkeling staat nooit stil

  • tools

Enhanced Windows Terminal prompt

November 22, 2020 (last updated: February 11, 2021) connect to GitHub

I often see a nice command prompt with context information like the current branch. So, I wanted to install that for myself since it would be nice to see what my path or git status is. The package used is oh my posh which you can find at GitHub repository.

Prerequisites

  • Windows Terminal (install through the Microsoft Store to get regular updates)
  • Git client (in my case Git for Windows)
  • when installing V3 with PowerShell script: PowerShell 6.0 or higher

Installation

The current version is V2, but I ended up going with V3 beta (Documentation V3).

V3 installation

In V3, the prompt is build up based on blocks that contain one or more segments each. A segment can be the path, git status, the time, etc. This way you can configure the prompt as you like. Check out the documentation for options and configuration: https://ohmyposh.dev/docs/configure

Install through the PowerShell script with the following command:

Install-Module -Name oh-my-posh -Scope CurrentUser -AllowPrerelease

Installation of V3 with PowerShell requires PowerShell 6 or higher. I downloaded the latest PowerShell version from the Microsoft Store (v7.1 in this case). More information on PowerShell at https://aka.ms/powershell.

Confirm PSGallery

AllowPreRelease error
If you get an error that -AllowPrerelease is not a known parameter, you can solve this by installing some extra modules. AllowPrelease error

Install-Module -Name PackageManagement -Repository PSGallery -Force
Install-Module -Name PowerShellGet -Repository PSGallery -Force

After that restart the shell and try the installation script for V3 again.

Theme

To get a list of the default themes:

Get-PoshThemes

I didn't need to go very fancy so I went with the theme Powerline

To get all of this to load when needed add the following to the PowerShell profile:

Import-Module oh-my-posh
Set-PoshPrompt -Theme powerline

Open the profile file from the PowerShell prompt with:

notepad $PROFILE

If it doesn't exist yet it can be created with this command as well.

Powerline Font

The command prompt relies on fonts with powerline support. If you don't have a powerline font installed or set you will see squares instead of the correct icons. If you don't have an appropriate font you can get them at https://www.nerdfonts.com. I got the default font for oh-my-posh, which is MesloLGM NF (install "Meslo LG M Regular Nerd Font Complete Mono Windows Compatible.ttf" from the downloaded zipfile).

Then update the font in PowerShell for the applications you are using the prompt in:

  • PowerShell (right-click the icon of the PowerShell window and properties) PowerShell properties
  • Windows Terminal (through Settings)
{
  ...
  "defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
  "profiles": {
    "defaults": {
    // SETTINGS TO APPLY TO ALL PROFILES
    "fontFace": "MesloLGM NF",
    "fontSize": 10,
  },
      "list": [
        ...
        ]
    }
  }
}

I chose to use the font type as my default but it's also fine to only configure it for a specific editor (https://docs.microsoft.com/en-us/windows/terminal/customize-settings/profile-settings).

  • Visual Studio Code (settings.json)
{
  ...
  "terminal.integrated.fontFamily": "MesloLGM NF",
  ...
}

Since I switched from PowerShell 5 to PowerShell 7, I also updated the default shell in the terminal to always use the PowerShell 7 version.

Configure the blocks and/or segments

By default, the segments for the theme include a segment with "type": "session", which displays the current user and hostname. I didn't feel this would add anything so I deleted this segment from the configuration file:

%USERPROFILE%\Documents\PowerShell\Modules\oh-my-posh\3.81.1\themes\powerline.omp.json

The version in the path of course depends on the installed version of oh-my-posh

Previous article Git bisect