Taking your PowerShell prompt to the next level with Windows Terminal and Oh my Posh 3
I love my pretty prompt that I use with Windows Terminal and Powershell. I also like using PSReadline to bring even more cool features to the CLI (Command Line Interface).
One of the best and easiest ways to get an awesome looking prompt on Windows is with Oh My Posh, and there's now Oh My Posh 3! Now, to be clear, you get to be pretty extra with these prompts and some people find them to be a turn off if there's too much bling. Remember: It's your prompt and you are in control. It's totally configurable - so configure it!
What do you need to start?
- Windows Terminal
- A super charged Cascadia Code font.
- I like CaskaydiaCove NF but any overkill nerd font will do. You can use Cascadia Code PL but you may want other glyphs.
- PowerShell (works on Windows, Linux, and Mac and is open source) and Oh my Posh
- Now, to be clear, you can use Oh My Posh on zsh, bash, fish, nu and other shells also, but I like PowerShell as my main shell.
Let's upgrade my Oh My Posh installation to Oh My Posh 3 and see what's new and changed, shall we?
Here's my current prompt:
There's an upgrading section in the docs, if you are going from an existing installation of Oh My Posh to v3. Let's check it out.
Looks like I just need to do this:
Update-Module -Name oh-my-posh -AllowPrerelease -Scope CurrentUser
That's...suspiciously...not difficult. Now, just add this text to your $profile (again, there are instructions for other prompts).
NOTE: Be sure to make sure that your paths are correct. The example assumes a c:\tools folder AND it assumes you have a ~\.poshthemes folder. Change those paths however you want, but if it doesn't work, it's likely a pathing issue.
Here's a clever feature, you can call "Get-PoshThemes" and see a PREVIEW of different prompt themes and pick one!
Hey that "jandedobbeleer" font is as extra as I am. I like it.
Set-PoshPrompt -Theme jandedobbeleer
The fun stuff is where you can add things like your current Azure subscruption, or your current kubectl, or even YouTube music. I like the dotnet option. Let me see how to change that.
There is an OhMyPosh executable you can get that will print your current config that you can then modify. Download the right version of that and put it in your PATH somewhere. I put mine in my sync'ed d:\dropbox\utils which makes it available on any machine, but that's just me.
NOTE: If it's a new release of OhMyPosh, it may not have built up reputation without a code signing cert, but ignore that for now. I submitted it as safe in smartscreen and you can too if you like.
I will get the current config and put it in the clipboard, then paste it into VS Code and modify it.
posh-windows-amd64.exe -print-config
Unicode! Note that you may not be able to | pipe this to clip.exe or > to a file as there's fancy Unicode in there and your shell may mangle the glyphs. I ended up copying the JSON manually directly by selecting it in Windows Terminal. You can also do this to get the json file
Write-PoshTheme | Out-File -FilePath ~/.go-my-posh.json -Encoding oem
If you want to copy in your own fancy glyph, use charmap.exe to copy the one you want. There's lots of choices in nerdfonts.
Pretty fancy! I've got the path, my git, and the current .NET Core SDK version in that path, as well as a heartbeat of the current CLI error code.
I've uploaded my ohmyposhv3.json as a Gist on GitHub. Next I think I'll look into how to make my own custom segment and make a Nightscout Blood Sugar segment and show my blood sugar in real time as I used to.
Sponsor: Have you tried developing in Rider yet? This fast and feature-rich cross-platform IDE improves your code for .NET, ASP.NET, .NET Core, Xamarin, and Unity applications on Windows, Mac, and Linux.
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.
About Newsletter