DEV Community

Cover image for Windows Git Prompt for WSL (Bash) and PowerShell
Michael Crump
Michael Crump

Posted on • Edited on

Windows Git Prompt for WSL (Bash) and PowerShell

AMA - Send me a text at +14252246702. I'll wrap up the Q&A into a dev.to blog post.

In this tutorial, we aim to bring life to our boring old PowerShell and Bash prompt by adding a colorful Git prompt. Kinda like this one!

Alt Text

PowerShell is steps 1-5 and WSL (Bash) steps 6-10. Many thanks to Gaurav Kamath for pointing this out.

Let's GOOOOO!!!

0.) Install WSL if you wish to have a Bash prompt.

1.) Install Windows Terminal for a productive terminal application and shells like Command Prompt, PowerShell, and WSL. Its main features include multiple tabs, Unicode and UTF-8 character support, a GPU accelerated text rendering engine, and custom themes, styles, and configurations.

2.) Install Git for Windows so that you can use git from the command line.

3.) Run these two commands in your PowerShell Window to install posh-git which is a PowerShell module that integrates Git and PowerShell by providing Git status summary information that can be displayed in the PowerShell prompt and oh-my-posh which is a theme engine for Powershell

Install-Module posh-git -Scope CurrentUser

Install-Module oh-my-posh -Scope CurrentUser
Enter fullscreen mode Exit fullscreen mode

4.) Within PowerShell, run notepad $PROFILE and add these lines to ensure the modules and theme is loaded upon startup.

Import-Module posh-git

Import-Module oh-my-posh

Set-Theme Paradox
Enter fullscreen mode Exit fullscreen mode

Close and reopen the PowerShell prompt and the changes should be applied. Simply navigate over to a Git repo to see changes.

Alt Text

5.) Set the Execution Policy to Unrestricted if you are unable to see the new theme or if it provides an error.

Set ExecutionPolicy Unrestricted
Enter fullscreen mode Exit fullscreen mode

6.) Install GoLang (or if you prefer Python for the Powerline add-in).

sudo apt install golang-go
Enter fullscreen mode Exit fullscreen mode

Run sudo apt update -y && sudo apt upgrade -y if it 404s during installation

7.) Add Powerline for a beautiful and useful low-latency prompt for your shell, written in go.

go get -u github.com/justjanne/powerline-go
Enter fullscreen mode Exit fullscreen mode

8.) Edit ~./bashrc with VS Code or Nano (ex. code ~./bashrc or nano ~./bashrc) and add the following information (source

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
Enter fullscreen mode Exit fullscreen mode

Alt Text

9.) Install a compatible Font for the terminal.

10.) Inside of the Windows Terminal, go to Settings and add the fontFace line to your profile.json under the Ubuntu and PowerShell section. Below is a snippet of my Ubuntu section.

    {
      "guid": "{123-38b7-51cf-b940-2309a097f518}",
      "hidden": false,
      "name": "Ubuntu",
      "source": "Windows.Terminal.Wsl",
      "fontFace": "Delugia Nerd Font"
    },
Enter fullscreen mode Exit fullscreen mode

Alt Text

Finished!

Did you like this? I streamed this live on Twitch. Follow me for upcoming developer streams.

Recap, What did we do today?

  • [x] Install Windows Terminal
  • [x] Install Git for Windows
  • [x] Install Posh-Git and Oh-My-Posh
  • [x] Import PowerShell Modules and Set Theme
  • [x] Change Execution Policy to All
  • [x] Install GoLang for Windows
  • [x] Run “sudo apt update” if it 404’s
  • [x] Install Powerline
  • [x] Edit ~/bashrc
  • [x] Install Font
  • [x] Add Font to Terminal Profile
  • [x] Closing

Things we learned

  • Installed the necessary Windows Terminal and Git for Windows applications, and why you would want to create a Git Prompt for WSL (Bash) and PowerShell
  • Installed modules and theme for PowerShell
  • Installed GoLang and Powerline (Git Prompt color)
  • Install font to and configure our Terminal Profile

Results

  • A brand new Git prompt for PowerShell and Bash

Sources

Top comments (5)

Collapse
 
dynamight profile image
Lord Explosion Murder

Hey! How do I do this to Git Bash terminal... The powershell looks great with these themes 😅 But how can I pimp up Git Bash like this

Collapse
 
gk profile image
Gaurav Kamath

For newbies, Instructions 6 onwards is meant for WSL. You need to run them in the WSL prompt.

Collapse
 
mbcrump profile image
Michael Crump

Thanks! I've included this at the top and mentioned you. I appreciate it.

Collapse
 
leandroruel profile image
Leandro RR • Edited

tried this today but i got "Set-Theme is not recognized as name or cmdlet" error.

Collapse
 
leandroruel profile image
Leandro RR

nevermind found the solution: github.com/JanDeDobbeleer/oh-my-po...