Reading time ∼1 mins

Customize the PowerShell prompt


This post is old. Some information may be inaccurate.

I've been using the PowerShell Core on Windows Terminal for a while. I wanted to customize the prompt to display > on a newline and the current Git branch along with the working directory. You can do this by overriding the Prompt function and saving it in one of the profiles. Here's the snippet that I'm using:

function prompt {
  "`n$env:Username@$env:ComputerName $($executionContext.SessionState.Path.CurrentLocation) $(git branch --show-current)`n$('>' * ($nestedPromptLevel + 1)) "

To have a colorful prompt, you can use VT Sequences as follows:

function prompt {
  "`n`e[32m$env:Username@$env:ComputerName`e[0m `e[34m$($executionContext.SessionState.Path.CurrentLocation)`e[0m `e[33m$(git branch --show-current)`e[0m`n$('>' * ($nestedPromptLevel + 1)) "

I was not familiar with VT Sequences but this Stack Overflow post helped me figure it out.