Hybrid Git Powershell Prompt.

A developer I work with came up with this neat PowerShell profile hack. I spend most of my day in a PowerShell window, and when working with repos, it can be handy to know where you are. This profile addition replaces your PowerShell prompt with the default (the path) unless you're in a git repo, where it then adds the branch you're on.

If you don't have a profile created  - run this first:  

New-Item -path $profile -type file -force

then edit it using

vim $profile

function prompt {
write-host $pwd -NoNewLine -ForegroundColor White
$branch = &git rev-parse --abbrev-ref HEAD
if($branch -ne $null)
write-host "[" -NoNewLine -ForegroundColor White
write-host $branch -NoNewLine -ForegroundColor Green
write-host "]" -NoNewLine -ForegroundColor White

Now you have a prompt that tells you where you are in your repositories!  

This site is a the personal space of Nick Couraud. While I touch on both personal and work related issues, everything here is my own opinion, and not necessarily reflective of my employer's views. Don't hold it against them.