How to make a pretty prompt in Windows Terminal with Powerline, Nerd Fonts, Cascadia Code, WSL, and oh-my-posh
I've blogged about Patching the new Cascadia Code to include Powerline Glyphs and other Nerd Fonts for the Windows Terminal but folks have asked very specifically, how do I make my prompt look like that?
Step One - Get the Terminal
Get Windows Terminal free from the Store. You can also get it from GitHub's releases but I recommend the store because it'll stay up to date automatically.
Note that if you were an early adopter of the Windows Terminal and you've released updated beyond 0.5, I'd recommend you delete or zero-out your profiles.json and let the Terminal detect and automatically recreate your profiles.json.
Step Two for PowerShell - Posh-Git and Oh-My-Posh
Per these directions, install Posh-Git and Oh-My-Posh. This also assumes you've installed Git for Windows.
Install-Module posh-git -Scope CurrentUser
Install-Module oh-my-posh -Scope CurrentUser
Run these commands from PowerShell or PowerShell Core. I recommend PowerShell 6.2.3 or above. You can also use PowerShell on Linux too, so be aware. When you run Install-Module for the first time you'll get a warning that you're downloading and installing stuff from the internet so follow the prompts appropriately.
Also get PSReadline if you're on PowerShell Core:
Install-Module -Name PSReadLine -AllowPrerelease -Scope CurrentUser -Force -SkipPublisherCheck
Then run "notepad $PROFILE" and add these lines to the end:
Import-Module posh-git
Import-Module oh-my-posh
Set-PoshPrompt -Theme Paradox
Now that word Paradox there is optional. It's actually the name of a theme and you can (and should!) pick the theme that makes you happy and use that theme's name here. I like Agnoster, Paradox, or Fish, myself. Read more over here. https://github.com/JanDeDobbeleer/oh-my-posh
Step Two for Ubuntu/WSL
There's a number of choices for Powerline or Powerline-like prompts from Ubuntu. I like Powerline-Go for it's easy defaults.
I just installed Go, then installed powerline-go with go get.
sudo apt install golang-go
go get -u github.com/justjanne/powerline-go
Add this to your ~/.bashrc. You may already have a GOPATH so be aware.
GOPATH=$HOME/go
function _update_ps1() {
PS1="$($GOPATH/bin/powerline-go -error $?)"
}
if [ "$TERM" != "linux" ] && [ -f "$GOPATH/bin/powerline-go" ]; then
PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"
fi
GOTCHA: If you are using WSL2, it'll be lightning fast with git prompts if your source code is in your Ubuntu/Linux mount, somewhere under ~/. However, if your source is under /mnt/c or /mnt anywhere, the git calls being made to populate the prompt are super slow. Be warned. Do your Linux source code/git work in the Linux filesystem for speed until WSL2 gets the file system faster under /mnt.
At this point your Ubuntu/WSL prompt will look awesome as well!
Fonts look weird? Uh oh!
Step Three - Get a better font
If you do all this and you see squares and goofy symbols, it's likely that the font you're using doesn't have the advanced Powerline glyphs. Those glyphs are the ones that make this prompt look so cool!
At the time of this writing there is active talk of getting Powerline and other Nerd Fonts into Cascadia Code, the new font that ships with Windows Terminal. In the short term, you can get a forked version of Cascadia Code called Delugia Code and download that.
Cascadia Code has been updated with a PL (Powerline) Glyph version! Go get it at https://github.com/microsoft/cascadia-code/releases and change the fontFace in your settings.json to "Cascadia Code PL"
"fontFace": "Cascadia Code PL"
Remember also you can get lots of Nerd Fonts at https://www.nerdfonts.com/, just make sure you get one (or generate one!) that includes PowerLine Glyphs.
Have fun!
Sponsor: Suffering from a lack of clarity around software bugs? Give your customers the experience they deserve and expect with error monitoring from Raygun.com. Installs in minutes, try it today!
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
On the Delugia documentation font face is named "Delugia Nerd Font" instead of "DelugiaCode NF"
It seems you need to avoid the "Mono" versions of the fonts for the ligatures to work.
"fontFace": "Delugia Nerd Font"
in the Windows Terminal config for Powershell core it worked.
For my own preferences, I've added -colorize-hostname (to differentiate environments at a quick glance) and -newline (because this prompts does take some space) to the options. My PS1 ended-up like this and I'm happy for now:
PS1="$($GOPATH/bin/powerline-go -colorize-hostname -newline -error $?)"
For anyone who'd rather have a smaller prompt in a single line, try playing with -condensed and -cwd-max-dir-size N (options described here); myself, I prefer the bigger prompt with a newline.
Thanks Scott!
I managed to get everything installed and running except the fonts with the Windows Terminal. The font works with Terminus (https://github.com/Eugeny/terminus) with the same PowerShell Core 7.0 preview 4.
Kinda odd but I will be fine with Terminus.
I am agree your points because I have follow this guidlines.
Microsoft.PowerShell_profile.ps1:28 char:26
+ $sysuptime = (Get-Date) � [System.Management.ManagementDateTime ...
+ ~~~
Unexpected token '�' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken
Is there any way, or plans to be able to launch the terminal from the Explorer file menu, and to be able to pin it to the quick launch?
compatibility problems. When I look at your blog in Safari,
it looks fine but when opening in I.E., it's got some overlapping
issues. I merely wanted to provide you with a quick heads up!
Apart from that, wonderful blog! https://vanzari-parbrize.ro/parbrize/parbrize-lancia.html
I needed to ask. Does operating a well-established blog like yours
take a lot of work? I am completely new to operating a blog but I do write in my journal everyday.
I'd like to start a blog so I can share my personal experience and thoughts online.
Please let me know if you have any ideas or tips for new aspiring bloggers.
Thankyou! https://anunturi-parbrize.ro/index.php?cauta=luneta+mazda
Comments are closed.