How to setup oh-my-posh in Windows Terminal

July 28, 2022

Updated 2024-02-26: Added instructions for oh-my-posh in git-bash in MINGW.
Updated 2024-02-22: Fixed winget package name conflict. Updated Meslo nerd font to v3.1.1.
Updated 2023-10-05: Added instructions for oh-my-posh in git-bash in Visual Studio.

While surfing the web (do people still say that?) I've seen several programmers have their shell decorated in a neat way, such as:

oh-my-posh screenshot

I think this looks great, so I wanted to learn how to set it up.

I've tried several multi-tabbed terminal emulators over the years... mostly ConEmu and Cmder, but I've been using Windows Terminal for a while now. Microsoft has iterated on it very fast recently, and it has some nice features that are fairly easy to configure. I also mostly do my work in the git-bash shell in Windows Terminal.

So this post will show you how to setup oh-my-posh in git-bash in a few different terminals for Windows 10 and up. The main instructions are in the first section for Windows Terminal, so you should follow them first, as other sections depend on those instructions. Let's get started:


Oh-my-posh in git-bash in Windows Terminal

  • Install Windows Terminal from the Microsoft Store
  • Install Git for Windows. This installs git-bash. During install, include the option to add git-bash to Windows Terminal settings.
  • Install Nerd Font MesloLGM Nerd Font (or something else from www.nerdfonts.com)
    • Extract MesloLGMNerdFont-Regular.ttf
    • Right click the ttf file -> Install for all users (On Windows11, you need to click Show more options first.)
  • Open Windows Terminal -> Click the down-arrow in the title bar -> Settings -> click Open JSON file in lower-left -> Add the following within profiles section:
"defaults": {
  "font":
  {
    "face": "MesloLGM Nerd Font"
  }
},
  • You can also add "size": 10 under the font section to set the font size.
  • Save settings.json
  • You may get a message saying it can't find the font file. Try restarting Windows Terminal. If still an issue, make sure the correct "face" name string is set by opening the Windows Font settings and search for meslo to see the correct face name.
  • Install oh-my-posh by running the following, which installs oh-my-posh.exe and adds it to your PATH, and adds POSH_THEMES_PATH environment var:
winget install JanDeDobbeleer.OhMyPosh
  • In the future, to update oh-my-posh, run:
winget upgrade JanDeDobbeleer.OhMyPosh
  • Restart Windows Terminal so it sees the new environment vars.
  • Tell git-bash to use oh-my-posh along with a specific theme:
    • oh-my-posh themes are installed to %localappdata%/Programs/oh-my-posh/themes
    • In git-bash, run nano ~/.bash_profile and add the following (change the theme file if you wish):
eval "$(oh-my-posh --init --shell bash --config ~/AppData/Local/Programs/oh-my-posh/themes/powerline.omp.json)"
  • Save, exit nano, and run source ~/.bash_profile then you should be able to see the new prompt.

Oh-my-posh in PowerShell in Windows Terminal

Same as above instructions for git-bash, but we need to add the oh-my-posh command and theme to our user's PowerShell $PROFILE.

Update: As of Feb 2024, I only had to run the "Set-ExecutionPolicy RemoteSigned" command as admin, then it just worked (assuming you followed the instructions above for git-bash.)

To see the location of your $PROFILE file (which may not actually be created yet even though it returns a path):

echo $PROFILE

You can create the profile (it won't overwrite if it already exists), by running:

if (!(Test-Path -Path $PROFILE)) {
  New-Item -ItemType File -Path $PROFILE -Force
}

Open your $PROFILE file with notepad $PROFILE and add the following, save, and reopen PowerShell:

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

If you get an error message saying you can't run your profile script, run powershell as admin, and run:

Set-ExecutionPolicy RemoteSigned


Oh-my-posh in git-bash in MINGW

If you followed the instructions for setting up Oh-my-posh in git-bash in Windows Terminal, it's also easy to get it working in git-bash in the MINGW terminal, which is the terminal that comes with Git for Windows. You already have oh-my-posh running within it, because it runs via ~/.bash_profile. So the only thing you need to do is tell MINGW to use your font.

Unfortunately, MINGW only shows a set of Monospaced fonts in it's GUI settings, so we have to do it via a config file. Open git-bash in MINGW, then type:

cd ~
nano .minttyrc

Use this as the contents of ~/.minttyrc

FontHeight=11
Font=MesloLGM Nerd Font

Save and exit nano, then restart git-bash / MINGW to see the updated prompt. Adjust the FontHeight as needed.

Thanks to this SO post for this solution.



Visual Studio Code - Terminal Font Setup

If you use Visual Studio Code, you'll probably notice that some of the characters in the prompt don't display correctly in it's integrated bash terminal. You can easily fix this by setting the terminal font to the same font we used above:

  • Opening settings by pressing ctrl-shift-p to open the command panel and type settings and open the settings UI.
  • Search the settings UI for terminal font and find the Terminal > Integrated: Font Family setting.
  • Set it to the same font face name you used above, which is MesloLGM Nerd Font in this case.
  • It should update immediately and you should be good to go.


Visual Studio - git-bash Terminal Setup

If you use Visual Studio and you've followed the instructions above to get oh-my-posh working in Git Bash, you can easily get it working in Visual Studio by following these steps (This was done in Visual Studio 2022):

  • Go to the Tools menu > Options.
  • Under Environment > Terminal, click Add.
  • Give it a Name. Something like Git Bash.
  • Shell Location will most likely be C:\Program Files\Git\bin\sh.exe, but maybe you installed Git Bash to a different volume/folder.
  • Set Arguments to --login -i
  • Optionally set Git Bash as the default Terminal by clicking Set as Default.
  • Click Apply and OK.
  • Under Environment > Fonts and Colors, in the Show settings for drop-down, select Terminal.
  • In the Font drop-down, select the nerd-font that you used with Git Bash above. I'm using MesloLGM Nerd Font.
  • Click OK.
  • Open a Terminal: Go to the View menu > Terminal. Open a Git Bash terminal (if it's not already default).