My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal (2024)

Sponsored By

I've long blogged about my love of setting up a nice terminal, getting the prompt just right, setting my colors, fonts, glyphs, and more. Here's some of my posts.

  • How to make a pretty prompt in Windows Terminal with Powerline, Nerd Fonts, Cascadia Code, WSL, and oh-my-posh
  • Patching the new Cascadia Code to include Powerline Glyphs and other Nerd Fonts for the Windows Terminal
  • What's the difference between a console, a terminal, and a shell?
  • Taking your PowerShell prompt to the next level with Windows Terminal and Oh my Posh 3

I want to take a moment to update my pretty prompt post with a little more detail and a more complex PowerShell $PROFILE, due to some changes in Oh My Posh, PowerShell, and the Windows Terminal. I doubt that this post is perfect and I'm sure there's stuff here that is a little extra. But I like it, and this post will serve as my "setting up a new machine" post until I get around to writing a script to do all this for me in one line.

I love my prompt.

My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal (1)

Let's get you set up!

Get PowerShell

I don't mean Windows PowerShell (that's "classic" now) I mean the .NET Core-powered cross-platform PowerShell. There's a LOT of ways to get it but I'm a Store person usually so I can get PowerShell (and it'll auto update) from the Microsoft Store or just "winget install Microsoft.PowerShell" from the command line with winget.

Get Windows Terminal and set a default Shell

Get Windows Terminal if you don't already have it, you can get Windows Terminal free from the Store. If you don't have access to the Microsoft Store, the builds are published on the GitHub releases page. It comes with a lovely font called Cascadia Code...but...

Now that you have Windows Terminal, you'll notice that it knows that you have PowerShell installed and will add it to your Windows Terminal dropdown menu! You can set PowerShell as your default Profile - that's the one you'll get by default when you make a new Tab - in settings:

My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal (2)

Upgrade your Terminal/Console Fonts

I like fonts with lots of Glyphs so I also download and Install Caskaydia Cove Nerd Font Complete. This is the same Cascadia Code font but MODIFIED to include hundreds of special characters that you can use to make your prompt cooler.

IMPORTANT NOTE: The string literal name of this font for use in settings or VS Code is "CaskaydiaCove NF". If you're using Cascadia Code, there are different strings for each. The NUMBER ONE question I get is 'why don't my glyphs/fonts show up right in Windows Terminal/VS Code?' and the answer is almost always "you're using the wrong font string." It's usually either an extra space or a missing space, so don't be afraid to double check.
My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal (3)

Remember that Windows Terminal has a lovely Settings UI but you can always click "open JSON file" to manage the settings.json as text if you prefer. Here's mine. Yours will be different and you should customize it! The Windows Terminal documentation is fantastic. Again, see how PowerShell is in BOLD? That's because it's my default.

My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal (4)

Now, let's add a little...spice...

Add "Oh My Posh" to your Shell

Oh My Posh has amazing docs so check them out. Do note that some stuff has changed, especially from v2 to v3.

EXCITING NOTE: Oh My Posh is portable and works on any shell, so I use it on both my "Pwsh" (PowerShell) in Windows and my Bash shells on WSL running Ubuntu.

You can install Oh My Posh with with PowerShell's "Install-Module" or with the platform-specific install instructions. I used the latter, which is somewhat new, but it's tomato/tomato, so use what works for you.

Again, read the docs but the idea on Windows is basically this (or get it from GitHub):

winget install JanDeDobbeleer.OhMyPosh
# restart shell to reload PATH

Then edit $PROFILE and add the following line, remembering at this point that oh-my-posh is an executable on the PATH.

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

I have changed my Oh My Posh from Jan's default to include my own stuff, and I keep my latest up in a GitHub Gist and also in my DropBox/OneDrive so it's always syncing to all my machines. Mine is this, after I download from my gist.

oh-my-posh --init --shell pwsh --config D:/Dropbox/ohmyposhv3-2.json | Invoke-Expression

Yours will vary. Again, read the docs and experiment! Once added, reload your profile for the changes to take effect, or restart your shell.

. $PROFILE

That .json file is filled with "segments" that are documented on the Oh My Posh site in a lot of detail. Overwhelming detail. You can add your computer's battery, your Azure Subscription, the dotnet or node version of your current folder, really anything. Even your Spotify songs. I'm going to make one that show my Blood Sugar.

Go explore Oh My Posh Themes and then modify them with your own additional Segments.

Again, note that your fonts will need the right glyphs or it will look weird.

Here's a GOOD prompt:

My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal (5)

Here's a BAD prompt with an issue!

My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal (6)

Why is it wrong? Either the .json file that is your config has been saved wrong or corrupted the Unicode Glyphs, or you've got a font that doesn't have those glyphs.

Re-assert your Git segment in Oh My Posh

Some folks want full git info, status, added, modified, untracked, etc and others just want the current git branch. Check the Git segment and the Posh Git segment to make sure you are getting the performance AND information you need.

I needed to turn on "display_stash_count" and "display_upstream_icon" in my config json, like this:

{
"type": "git",
"style": "powerline",
"powerline_symbol": "",
"invert_powerline": false,
"foreground": "#193549",
"background": "#fffb38",
"leading_diamond": "",
"trailing_diamond": "",
"properties": {
"display_status": true,
"display_stash_count": true,
"display_upstream_icon": true
}
},

Again, this is all optional and affect performance slightly, but be aware of these properties. I believe I have these set the right way I want them in my public gist. Here is me moving around my source code with "z" in stead of cd, but note the prompt changes.

My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal (7)

Turn your PowerShell directories up to 11 with Terminal-Icons

Is your prompt not extra enough? That's because your directory listing needs color AND cool icons!

Install-Module -Name Terminal-Icons -Repository PSGallery

And then add one line to my $profile (edit with "code $profile"):

Import-Module -Name Terminal-Icons

Sweet!

My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal (8)

How far is too far?

At this point you're basically done, but I also LOVE PSReadLine. It's great generally but also nice for bash and Emacs types who are moving to PowerShell or use PowerShell for work.

I've added features like "ctrl shift b" at the command line will run "dotnet build." Why? Because I can and because it's muscle memory so I'm making my prompt work for me.

You can also add Predictive Autocomplete to your prompt if you like but I'll leave that as an exercise to the reader! My PowerShell profile is on a public gist, and while it's not perfect and likely has issues, it works for me!

My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal (9)

Enjoy! Thanks to the Windows Terminal Team and the always lovely Jan De Dobbeleer from Oh My Posh, as well as Brandon Olin from Terminal Icons.

Check out our Sponsor! YugabyteDB is a distributed SQL database designed for resilience and scale. It is 100% open source, PostgreSQL-compatible, enterprise-grade, and runs across all clouds. Sign up and get a free t-shirt!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal (10) My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal (11)
About Newsletter

Hosting By
My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal (13)

Comment on this post [17]

Share on or or use the Permalink

September 01, 2021 10:55

Inspired by your series of articles, I've written a quick Windows PowerShell script that mostly sets up the tooling shown here.
It might help you write yours and help others.

https://github.com/springcomp/my-box

My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal (14) Springcomp

September 01, 2021 12:48

How do you run a prompt as administrator? There doesn't appear to be any way to do it per tab and there is no option to do it for Windows terminal as a whole and the Ctrl+Shift+click doesn't work either.

This kind of ruins it for me, I regularly run iisreset and that requires admin rights.

My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal (15) Peter

September 01, 2021 17:34

Shift + Right-Click on Windows Terminal icon and the context menu give you "Run as Administrator" , provided your account has administrator permission.
Selecting that option gives you the access you need to run commands with elevated privilege. Use at your own risk!

My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal (16) Jon

September 01, 2021 22:24

@Peter You can set programs to always run as admin under the Compatibility tab in Properties

My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal (17) Zachariah

September 01, 2021 22:46

For some reason oh-my-posh is getting flagged by bitdefender. So it won't run on my device.

September 02, 2021 2:30

PowerShell 7.1.4 doesn't appear to include winget and it's not in the Windows Store. Where's the bes/safestt place to get winget from?

My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal (19) EvilKiru

September 02, 2021 3:44

Protip - If you need admin rights in your Windows Terminal session...

choco install -y gsudo

Then "sudo [command here]" (or just simply "sudo") to elevate - you'll get a UAC prompt, after which you'll have all the power.

You're welcome.

My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal (20) CaptainStealthy

September 02, 2021 13:00

What is $PROFILE? Where can I find it, and how to add oh-my-posh for it?

"Then edit $PROFILE and add the following line" - could you give me more details about this step?

Add this to where? "oh-my-posh --init --shell pwsh --config ~/jandedobbeleer.omp.json | Invoke-Expression"

My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal (21) Marton Lajos

September 02, 2021 13:51

I think you will never stop tinkering your Powershell prompt. As always excellent post. Here is my two cents you can also include ZLocation. I started liking this a lot and now my cd command is like magic.

My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal (22) Ferose Khan J

September 03, 2021 3:38

@Marton: $PROFILE is an environment variable that points to your personal powershell profile, which starts out not existing. To access it, edit $PROFILE using text editor. For example:

notepad $PROFILE

Which tells me the file doesn't exist, which is to be expected, because I haven't used it yet.

After you insert the line, save the file and restart your shell.

My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal (23) EvilKiru

September 03, 2021 4:09

Nice.

If anyone is looking for a Bash, ZSH, Fish, and tcsh shell that looks similar, this one is great.

https://github.com/b-ryan/powerline-shell

September 03, 2021 4:13

It looks like powerline is in use with this solution?

September 03, 2021 4:23

i've got a bad prompt -- and it's ugly af :( HELP!


Why is it wrong? Either the .json file that is your config has been saved wrong or corrupted the Unicode Glyphs, or you've got a font that doesn't have those glyphs.

huh? what does that mean? how do I begin to figure out what's wrong?

My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal (26) Ty A

September 04, 2021 15:18

Thanks. It's amazing.

September 06, 2021 17:19

Hi Scott. Excellent post (as always). I've been customizing my prompt with your series since first post on this. Thanks!

My two cents to dotnet developers to add to oh my posh. I almost always mistype aspnetcore_environment, so this shows which environment you have set (and if you type it right)


{
"type": "envvar",
"style": "powerline",
"powerline_symbol": "\uE0B0",
"foreground": "#ffffff",
"background": "#0077c2",
"properties": {
"var_name": "ASPNETCORE_ENVIRONMENT"
}
}

Thanks again!

My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal (28) German

September 07, 2021 22:34

These articles (and not just the Powershell ones, either) have piqued my interest in Terminal, Powershell and Linux to such a degree that I converted an old laptop to run Elementary, and I've decked out Terminal in work and home environments. The tips in the comments are great, too. Thanks, everybody!

My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal (29) John Dunagan

September 09, 2021 11:18

https://see5.net/price-of-building-online-store/
https://see5.net/the-best-web-design-company/
http://see5.net/
https://see5.net/shop-creator/
https://see5.net/price/
https://see5.net/how-to-create-website/

Comments are closed.

My Ultimate PowerShell prompt with Oh My Posh and the Windows Terminal (2024)
Top Articles
Latest Posts
Article information

Author: Rob Wisoky

Last Updated:

Views: 5892

Rating: 4.8 / 5 (68 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Rob Wisoky

Birthday: 1994-09-30

Address: 5789 Michel Vista, West Domenic, OR 80464-9452

Phone: +97313824072371

Job: Education Orchestrator

Hobby: Lockpicking, Crocheting, Baton twirling, Video gaming, Jogging, Whittling, Model building

Introduction: My name is Rob Wisoky, I am a smiling, helpful, encouraging, zealous, energetic, faithful, fantastic person who loves writing and wants to share my knowledge and understanding with you.