Oh My Posh is a great extension to show a useful Git prompt in your terminal. It actually works on Windows, even if we need some extra steps to turn this prompt
into this
Installation
We can use the official installation guide an install Oh My Posh from the Windows Store:
This installer gets you the *.exe, but otherwise you will not see any change to your prompt.
Choose a font
We need to choose a font that supports the Nerd Fonts icons, otherwise we end up with a broken prompt. I like the JetBrains Mono font, but you can use any font from the font download page. If you are unsure, you can try many fonts on ProgrammingFonts.org.
Download and install the font in Windows
We can download the font directly from Nerd Fonts and the open the *.zip file. I double-clicked the JetBrains Mono Medium Nerd Font Complete Windows Compatible.ttf file to start the font preview tool from Windows:
If you like what you see, you can click on the Install button to use it inside your applications.
Prepare the Windows Terminal
Use the key combination Ctrl + Shift + , to open the settings file. Search for profiles and change the defaults entry to this:
1 2 3 4 5 6 7 |
"profiles": { "defaults": { "font": { "face": "JetBrainsMono NF" } }, |
Configure the prompt in Windows Terminal
Try to open the configuration file with this command (stop if it does not already exists!):
1 |
notepad $PROFILE |
If it does not exist, stop Notepad and run this command:
1 |
New-Item -Path $PROFILE -Type File -Force |
Now there should be no error message when you open the configuration in Notepad again:
1 |
notepad $PROFILE |
Copy this line to your $PROFILE file:
1 |
oh-my-posh init pwsh | Invoke-Expression |
You can start a new terminal or run this command to activate your changes in $PROFILE:
1 |
. $PROFILE |
This should activate Oh My Posh and gives you a prompt like this one:
Fix Visual Studio
If we open a Developer Power Shell window, we will see somethings like this:
We need to choose our Nerd Font to fix this issue. Open the Tools / Options settings dialog and go to Environment / Fonts and Colors. Select the Terminal settings and change the font:
When we save the changed settings, Visual Studio reloads the Power Shell and now it should look as expected:
Fix VS Code
To fix a broken prompt in VS Code, go to File / Settings and search for @feature:terminal font. Set your font there if you only want it to work only in the Terminal:
If you want to use your font everywhere, you can change the setting for Editor: Font Family that is linked in the Terminal fonts settings.
This gives you the correct prompt in VS Code:
If you see no Oh My Posh prompt at all, you may run the wrong PowerShell version. On my machine I have PowerShell and Windows PowerShell – but only the Windows PowerShell works.
Conclusion
There are a few extra steps we need to get Oh My Posh working in all our development environments. But as soon as we went through the hoops it works and gives us the additional information that makes working with Git a lot nicer.