How I have configured my Windows PowerShell command line prompt using Oh My Posh, PSReadLine, posh-git & Terminal-Icons

Naturally, all real work is done on the command line! Having a great command line experience makes all the difference. Life’s too short to have a crappy command line (or, horror of horrors, have to click on buttons in a GUI :))

Inspired by Scott Hanselman’s post, here is how I have configured my command line using Oh My Posh. Follow his instructions to get started.

Tools To Install

Oh My Posh Configuration

Here is my personal terminal theme.

  1. path – the whole path I am working in
  2. poshgit – shows branch name & # of changes (posh-git, you will have to install this)
  3. root – whether I am running as root (or Windows Administrator), adds a lightning bolt to the end of the prompt
  4. exit – shows the error code from the previous command (if there was one, such as xERROR)
  5. prompt – shows a blue arrow on a newline

Here is the whole file.

{
  "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
  "blocks": [
    {
      "type": "prompt",
      "alignment": "left",
      "segments": [
        {
          "type": "path",
          "style": "plain",
          "foreground": "#ffffff",
          "properties": {
            "prefix": "",
            "style": "full"
          }
        },
        {
          "type": "poshgit",
          "style": "plain",
          "foreground": "#C2C206"
        },
        {
          "type": "root",
          "style": "plain",
          "foreground": "#B5B50D"
        },
        {
          "type": "exit",
          "style": "plain",
          "foreground": "#C94A16",
          "properties": {
            "prefix": "x"
          }
        }
      ]
    },
    {
      "type": "prompt",
      "alignment": "left",
      "newline": true,
      "segments": [
        {
          "type": "text",
          "style": "plain",
          "foreground": "#007ACC",
          "properties": {
            "prefix": "",
            "text": "\uE602"
          }
        }
      ]
    }
  ],
  "final_space": true
}

Make sure you reference this in your $PROFILE PowerShell file.

oh-my-posh --init --shell pwsh --config "C:\Users\jordanbean\ohmyposhv3-v2.json" | Invoke-Expression

Import-Module PSReadLine
Import-Module -Name Terminal-Icons
Import-Module posh-git

Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineOption -EditMode Windows

$env:POSH_GIT_ENABLED = $true

Other

I also have PSReadLine installed. This remembers your previous commands and displays an interactive list. Makes it so much easier to find previous commands (especially longer commands).

Finally, I have Terminal-Icons installed to provide a glyph for listing directory contents.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *