Posh-git for Powershell

I don’t know how I discovered this, but it is all but indispensable now…
A PowerShell environment for Git http://dahlbyk.github.io/posh-git/

When you are in a local git repo, posh-git shows you basic output of the “git status” command.  For example:
C:\users\hxchba\dropbox\posh-git [cbMods +1 ~2 -0 !]>

Displayed are the branch name, count of untracked files, count of modified files, and count of deleted files.

If I stage one file for commit (git add <filename>), the prompt will look like this:
C:\users\hxchba\dropbox\posh-git [cbMods +0 ~1 -0 |+1 ~2 -0 !]>

The easiest way (that I have found) to load posh-git is via the profile.example.ps1 file (included with posh-git) — it configures the prompt to show git status.
(Of course, if you already have a custom prompt, this could cause some issues….)

One problem I run in to in the corporate setting was having to work with very long UNC paths.  For example:

I created a function – ShortenPath – to shorten long strings (script is attached below). Then, I added it to posh-git’s profile.example.ps1, where the prompt function is defined.
After ShortenPath is used:

See my modified profile.example.ps1 for all the details.

(After downloading, change the .txt to .ps1, of course.)




Leave a Reply

Your email address will not be published. Required fields are marked *

Are you human? * Time limit is exhausted. Please reload CAPTCHA.

Protected with IP Blacklist CloudIP Blacklist Cloud