Skip to content

Instantly share code, notes, and snippets.

@plembo
Last active September 19, 2021 19:35
Show Gist options
  • Save plembo/4293c1f3dacae95a2ce93389328944bb to your computer and use it in GitHub Desktop.
Save plembo/4293c1f3dacae95a2ce93389328944bb to your computer and use it in GitHub Desktop.
Powerline on bash and PowerShell for Linux and Windows

Powerline on bash and PowerShell for Linux and Windows

NOTE: If you find yourself getting thinking you may have gotten way too far down into the weeds with this, you might want to consider a much less involved alternative: bash-git-prompt (that's what I'm now using on all my Linux machines).

To be clear, this gist will focus on Powerline for the Gnome terminal on Linux and for PowerShell Core on Windows 10, because those are the combinations I use in my daily work.

powerline image

There are two different open source products that make it easier to implement Powerline for bash and PowerShell:

Oh My Bash for bash on Linux.

Oh My Posh for PowerShell.

The main difficulty I had in setting this up was in getting a font package that included the Powerline glyphs.

For on Ubuntu Linux 18.04 and forward I use the original powerline fonts as installed by the included install.sh bash script.

For Oh My Posh on Windows 10, I also used the original powerline fonts (hey, it comes with a handy install.ps1 PowerShell script, after all).

As a result of all this, I'm now using "DejaVu Sans Mono for Powerline" as my console and editor font on both platforms.

Oh My Bash on Ubuntu 18.04+

  1. Install the original powerline fonts:
$ git clone https://github.com/powerline/fonts.git
$ cd fonts
$ bash install.sh
  1. Install Oh My Bash :
$ sh -c "$(curl -fsSL https://raw.github.com/ohmybash/oh-my-bash/master/tools/install.sh)"
  1. Set your preferred theme by editing OSH_THEME=[theme name] in your ~/.bashrc file and save.
OSH_THEME="powerline"
  1. Re-launch Gnome terminal and change the font it uses to "DejaVu Sans Mono for Powerline Book". This is located under Edit... Preferences... Profiles... [Profile Name]... Text... Custom font. Then restart the terminal.

  2. For the terminal in Visual Studio Code, go to File... Preferences... Settings... Text Editor... Font. Set it to "DejaVu Sans Mono for Powerline" and save.

Oh My Posh on Windows 10

Note that the procedure for Windows uses version 2 of Oh My Posh. The newer version 3 is still in beta and works completely differently.

  1. Make sure Windows Terminal and PowerShell Core have been installed from the Microsoft Store.
  2. Install the original powerline fonts:
PS> git clone https://github.com/powerline/fonts.git
PS> cd fonts
PS> pwsh install.ps1
  1. Launch Windows Terminal and execute the following commands:
PS> Install-Module posh-git -Scope CurrentUser
PS> Install-Module oh-my-posh -Scope CurrentUser
PS> Install-Module -Name PSReadLine -Scope CurrentUser -Force -SkipPublisherCheck
  1. Edit (or create) the PowerShell $PROFILE file to append the lines that will invoke the shell generator:
PS> notepad $PROFILE

NOTE: Change your theme using Set-Theme.

Import-Module posh-git
Import-Module oh-my-posh
Set-Theme powerline
  1. Edit the Windows Terminal settings.json (you can get to this from the "Settings" in the Windows Terminal gui) to set "fontFace" to "DejaVu Sans Mono for Powerline", and save:
{
    "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
    "hidden": false,
    "name": "PowerShell",
    "source": "Windows.Terminal.PowershellCore",
    "fontFace": "DejaVu Sans Mono for Powerline"
},
  1. Close and re-launch Windows Terminal, and choose PowerShell Core (if it isn't your default shell).

  2. For the terminal in Visual Studio Code, go to File... Preferences... Settings... Text Editor... Font. Set it to "DejaVu Sans Mono for Powerline" and save.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment