Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display git tag name in the prompt #233

Closed
wants to merge 11 commits into from
21 changes: 20 additions & 1 deletion GitPrompt.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ $global:GitPromptSettings = New-Object PSObject -Property @{
BranchBehindAndAheadStatusSymbol = [char]0x2195 # Up & Down arrow
BranchBehindAndAheadStatusForegroundColor = [ConsoleColor]::Yellow
BranchBehindAndAheadStatusBackgroundColor = $Host.UI.RawUI.BackgroundColor

EnableTagDisplay = $true
TagForegroundColor = [ConsoleColor]::DarkGray
TagForegroundBrightColor = [ConsoleColor]::Gray
TagBackgroundColor = $Host.UI.RawUI.BackgroundColor

BeforeIndexText = ""
BeforeIndexForegroundColor = [ConsoleColor]::DarkGreen
Expand Down Expand Up @@ -157,8 +162,22 @@ function Write-GitStatus($status) {

Write-Prompt (Format-BranchName($status.Branch)) -BackgroundColor $branchStatusBackgroundColor -ForegroundColor $branchStatusForegroundColor

if ($s.EnableTagDisplay) {
$tag = Get-Tag
if ($tag) {
Write-Prompt "|$($tag)" -BackgroundColor $s.TagBackgroundColor -ForegroundColor $s.TagForegroundColor
}
}

if ($branchStatusSymbol) {
Write-Prompt (" {0}" -f $branchStatusSymbol) -BackgroundColor $branchStatusBackgroundColor -ForegroundColor $branchStatusForegroundColor
Write-Prompt (" ") -BackgroundColor $branchStatusBackgroundColor -ForegroundColor $branchStatusForegroundColor
if ($status.AheadBy -ge 1) {
Write-Prompt ("{0}" -f $status.AheadBy) -BackgroundColor $branchStatusBackgroundColor -ForegroundColor $branchStatusForegroundColor
}
Write-Prompt ("{0}" -f $branchStatusSymbol) -BackgroundColor $branchStatusBackgroundColor -ForegroundColor $branchStatusForegroundColor
if ($status.BehindBy -ge 1) {
Write-Prompt ("{0}" -f $status.BehindBy) -BackgroundColor $branchStatusBackgroundColor -ForegroundColor $branchStatusForegroundColor
}
}

if($s.EnableFileStatus -and $status.HasIndex) {
Expand Down
4 changes: 4 additions & 0 deletions GitUtils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ function InDisabledRepository {
return $false
}

function Get-Tag {
return git tag --points-at HEAD
}

function Enable-GitColors {
Write-Warning 'Enable-GitColors is Obsolete and will be removed in a future version of posh-git.'
}
Expand Down