An easier way would be just installing the Powershell module posh-git. It comes out of the box with the desired prompt:
The Prompt
PowerShell generates its prompt by executing a prompt function, if one exists. posh-git defines such a function in profile.example.ps1 that outputs the current working directory followed by an abbreviated git status:
C:UsersKeith [master]>
By default, the status summary has the following format:
[{HEAD-name} +A ~B -C !D | +E ~F -G !H]
(For installing posh-git I suggest using psget)
If you don't have psget use the following command:
(new-object Net.WebClient).DownloadString("https://raw.githubusercontent.com/psget/psget/master/GetPsGet.ps1") | iex
To install posh-git use the command:
Install-Module posh-git
To ensure posh-git loads for every shell, use the Add-PoshGitToProfile
command.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…