Add Git Information (and more) to Windows Terminal (or PowerShell)

Add Git Information (and more) to Windows Terminal (or PowerShell)

I’m a fan of Windows Terminal – it makes it easier for me to manage my terminal windows in a tabbed interface and makes it easy to access a terminal for either my Windows machine or the WSL guest in one interface.

But sometimes, it is useful to add a bit more context to your terminal window, besides just your current working directory. This additional information might be the current Git branch (or other Git repository details), execution time of commands, system resource usage, or a wide range of other information.

These details can be added to your terminal prompt by using Oh My Posh. With Oh My Posh, you can customise your prompt by editing a configuration file (known as a theme), and make your Windows Terminal or PowerShell prompt work exactly as you’d like.

You can setup Oh My Posh by following the steps below, and then either use one of the provided themes or create your own!

Install Windows Terminal

This isn’t strictly required, since Oh My Posh will work just fine with PowerShell, but I’ve found it a very useful program to have installed. If you’d like you can install this by using the following command in PowerShell.

winget install Microsoft.Terminal

Install a Nerd Font

Many of the themes included with Oh My Posh make use of a Nerd Font to display icons in the terminal window. This might be a Git, CPU, or other icon to make things look a bit more presentable (and give you more options in your customisation).

Head over to the Nerd Fonts download page and download a font you like. Any of these should do, though the Meslo Nerd Font is recommended by Oh My Posh. After the font has been downloaded, install the “Meslo LG M Regular Nerd Font Complete Mono” font.

After the install has completed, we need to change the default font to be “Meslo LGM Nerd Font”.

Change the font in Windows Terminal

To change the font in Windows Terminal, you can follow these steps.

  • Open the Settings panel
  • Select the Default profile menu item
  • Switch to the Appearance tab
  • Select the “Meslo LGM Nerd Font Mono” font from the drop down

Change the font in PowerShell

To change the font in PowerShell, you can follow these steps.

  • Open PowerShell
  • Right-click on the title bar and select the Properties menu item
  • Switch to the Font tab
  • Select the “Meslo LGM Nerd Font Mono” font from the select box

Now the font is set we can carry on to the next step!

Install Oh My Posh

Installing Oh My Posh is a pretty easy one-liner when using winget! Run the following command in a PowerShell window and it should take care of the process.

winget install JanDeDobbeleer.OhMyPosh

After that has completed, we now need to modify your PowerShell profile to load Oh My Posh.

Amend the PowerShell profile

This step tells PowerShell to load Oh My Posh when it opens. This will apply your configuration and give you your customised prompt.

You can open your profile to be edited in Notepad by running the command below in PowerShell. If you receive a message saying the file doesn’t exist, you will need to create it by clicking “Yes” in the prompt.

notepad $profile

Now we need to add the following to the file.

oh-my-posh --init --shell pwsh --config ~~/AppData/Local/Programs/oh-my-posh/themes/jandedobbeleer.omp.json | Invoke-Expression

After this has been added, we can save the file and close Notepad.

Reload your profile

After you have changed your profile, you will need to reload it for the changes to take effect. You can do this by closing and opening the PowerShell window or by running the command below.

. $profile

This should cause your profile to reload, and you should see your new prompt!

Get creative with the configuration

You can now start customising your prompt as much as you’d like or try out one of the included themes. Oh My Posh also has lots of documentation on how to create your own themes including information on the wide variety of segments available.

Just remember to reload your profile after you modify your theme for the changes to take effect!