Customize Powershell Prompt Message

At work, I use [PowerShell] ( a lot, mostly for Git commands. By default, the powershell prompt message shows you the full path of the current working directory. i.e. something like this;

PS C:\vraa\workspace

Which is fine, but I'd like this prompt to be short and informative. In short, I'd want the prompt to:

  • Show only the folder name, instead of full path.
  • Show the current branch name if inside a Git repo.

Powershell provides an option to customize its behavior. You can write your customization, in terms of functions, and keep them in your $PROFILE file. So, in order to achive my requirement, I used following function.

  1. In Powershell, type notepad.exe $PROFILE.
  2. Add following function there.
function prompt{
  $p = Split-Path (
     ) -Leaf
  git branch | foreach{
    if($_ -match "^\*(.*)"){
     $p += " [" + $matches[1] + " ] "
  $p = $p + ">"
  Write-Host $p -NoNewline -ForegroundColor Green
  return " "

Be sure to keep the function name as prompt. Save and restart Powershell.

After the above customization, when you are in a normal folder, Powershell prompt will look like this:


And, when inside a Git repo, the prompt message will look like:

gitrepo [ master ] >

Thanks to [this] ( for the script to detect current Git branch name.

So, what is your [Powershell customization] (

Chat with the Author

This post was written by Veera, a software developer by profession and a maker by passion.

You will be taken to where you can edit the tweet before posting.

If you liked my writing, you may like my products