How to set up a theme for the Windows Terminal prompt with Git status indication / session / error / GlyphLinked fonts

oh my posh powerline

This post deals with setting up a theme for the prompt command line of PowerShell and WSL (Ubuntu) in Windows Terminal. The theme allows you to get:

  • displaying indications about the status of Git repositories when the current path of the shell is in a repository
  • indication of order errors
  • indications about administrator
  • indication of the current session (admin, order errors, user)
  • possibility of setting up and creating a theme
  • compatibility with the PowerShell console
  • compatibility with the WSL Ubuntu console

1. Installation of posh-git and oh-my-posh for PowerShell


Prerequisite:

  • Windows Terminal must be installed (version 18362.0 or higher (v1903-Build 10.0.18362.0), ARM64 architecture, x64, x86). You can download it from the app store
  • Git for Windows must be installed (downloadable from https://gitforwindows.org/)

Online order installation operations:

These commands are to be launched from a PowerShell 6.2.3 version console or later.

Install-Module posh-git -Scope CurrentUser
Install-Module oh-my-posh -Scope CurrentUser

You will eventually be asked to install the NuGet supplier for PowerShellGet (in this case accept installation). PSGallery’s repository will also have to be approved to allow installation.

Activation of the theme:

Set-Prompt
Set-Theme Paradox

you can check the current configuration of oh-my-posh with the $ThemeSettings command and posh-git configuration with the $GitPromptSettings command. To see the colors of the theme you have the Commands Show-ThemeColors and Show-Colors

powershell prompt with theme
powershell prompt with theme

That’s it! The PowerShell’s prompt was replaced by the prompt with a theme. You still have to think about editing the shell’s user profile to keep this setting with each PowerShell launch. To do this, launch the command notepad $PROFILE command from PS and fill the file (it is created if it doesn’t exist yet) as follows, then save it.

powershell profile
powershell profile

Choice of the theme:

In previous examples, reference was made to the theme called Paradox. It should be noted that other predefined prompt themes exist and you just have to replace the name in the previous examples to change the theme. Here’s the list of pre-defined themes from oh-my-posh (images and list from Jan De Dobbeler    @  https://github.com/JanDeDobbeleer/oh-my-posh)

  • Agnoster agnoster
  • Paradox paradox
  • Sorin sorin
  • Darkblood darkblood
  • Avit darkblood
  • Honukai honukai
  • Fish fish
  • Robbyrussel robbyrussel

Character font configuration:

This step is important because the installed modules use extended glyphs for the display of the prompt (posh-git). You’ve probably noticed the presence of square characters with arrow inside in the prompt text if you’ve reproduced the previous installation steps. To correct this problem, a suitable font should be installed in Windows and its use by the shell set up.

I advise you to use the font “Cascadia PL” available at https://github.com/microsoft/cascadia-code/releases . Download CascadiaPL.ttf and have the Windows 10 pop-up menu“installed”on the file.

To implement the font in PowerShell, open windows Terminal settings (button [V] items settings) and edit the profiles.json file by adding the in the default section or in the shell section of your choice, the setting: “FontFace”: “Cascadia Code PL”

This step is explained in detail in the post: Windows Terminal – Installation and configuration : full tutorial

visualization of extended glyphs in the prompt PowerShell
visualization of extended glyphs in the prompt PowerShell

Other extended glyph fonts are available on the site: https://www.nerdfonts.com/

2. Installation of powerline for the shell WSL Ubuntu

What we’ve seen before only applies to the PowerShell script. It takes another manipulation to get an equivalent prompt in the Ubuntu shell. There are several tools available, here we will be interested in powerline with a module written in go. These operations are to be carried out from the shell ubuntu:

sudo apt update
sudo install golang-go
go get -u github.com/justjanne/powerline-go
Install-Module oh-my-posh -Scope CurrentUser

It is necessary to think to add to the user profile a bit of script that activates the theme of the prompt shell, by editing the file ~/.bashrc (with vi for example):

GOPATH=$HOME/go
function _update_ps1() {
PS1="$($GOPATH/bin/powerline-go -error $?)"
}
if [ "$TERM" != "linux" ] && [ -f "$GOPATH/bin/powerline-go" ]; then
PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"
fi

You should also consider adding the font that supports extended glyphs as seen previously in Windows Terminal profiles.json. After relaunching the shell, the prompt is actually modified, as visible in the following example:

prompt showing statuses gits, ubuntu at the top and powershell at the bottom
prompt showing statuses gits, ubuntu at the top and powershell at the bottom