From 6babbc44c13f4172457c8ab9dc3f18612c43c00e Mon Sep 17 00:00:00 2001 From: Alan Bridgewater Date: Fri, 19 Feb 2016 11:09:33 -0800 Subject: [PATCH 1/3] Show AheadyBy/BehindBy counts based on configuration Add prompt setting BranchBehindAndAheadDisplay: If only behind or ahead,: If set to "Full" or "Compact", display count along with appropriate arrow, otherwise just show the arrow If both behind and ahead: If set to "Full", then display count along with arrow indicating direction of behind/ahead If set to "Compact", display the behind count immediately next to double-arrow, then ahead count If set to "Minimal" (or not recognized), display the old behavior of just the double-arrow. --- GitPrompt.ps1 | 53 ++++++++++++++++++++++++++++++--------------- profile.example.ps1 | 4 ++++ 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/GitPrompt.ps1 b/GitPrompt.ps1 index 865136efa..e96047ff0 100644 --- a/GitPrompt.ps1 +++ b/GitPrompt.ps1 @@ -63,20 +63,23 @@ $global:GitPromptSettings = New-Object PSObject -Property @{ WorkingForegroundBrightColor = [ConsoleColor]::Red WorkingBackgroundColor = $Host.UI.RawUI.BackgroundColor - EnableStashStatus = $false - BeforeStashText = ' (' - BeforeStashBackgroundColor = $Host.UI.RawUI.BackgroundColor - BeforeStashForegroundColor = [ConsoleColor]::Red - AfterStashText = ')' - AfterStashBackgroundColor = $Host.UI.RawUI.BackgroundColor - AfterStashForegroundColor = [ConsoleColor]::Red - StashBackgroundColor = $Host.UI.RawUI.BackgroundColor - StashForegroundColor = [ConsoleColor]::Red + EnableStashStatus = $false + BeforeStashText = ' (' + BeforeStashBackgroundColor = $Host.UI.RawUI.BackgroundColor + BeforeStashForegroundColor = [ConsoleColor]::Red + AfterStashText = ')' + AfterStashBackgroundColor = $Host.UI.RawUI.BackgroundColor + AfterStashForegroundColor = [ConsoleColor]::Red + StashBackgroundColor = $Host.UI.RawUI.BackgroundColor + StashForegroundColor = [ConsoleColor]::Red ShowStatusWhenZero = $true AutoRefreshIndex = $true + # Valid values are "Full", "Compact", and "Minimal" + BranchBehindAndAheadDisplay = "Full" + EnablePromptStatus = !$Global:GitMissing EnableFileStatus = $true RepositoriesInWhichToDisableFileStatus = @( ) # Array of repository paths @@ -124,41 +127,55 @@ function Write-GitStatus($status) { if ($status -and $s) { Write-Prompt $s.BeforeText -BackgroundColor $s.BeforeBackgroundColor -ForegroundColor $s.BeforeForegroundColor - $branchStatusSymbol = $null + $branchStatusText = $null $branchStatusBackgroundColor = $s.BranchBackgroundColor $branchStatusForegroundColor = $s.BranchForegroundColor if (!$status.Upstream) { - $branchStatusSymbol = $s.BranchUntrackedSymbol + $branchStatusText = $s.BranchUntrackedSymbol } elseif ($status.BehindBy -eq 0 -and $status.AheadBy -eq 0) { # We are aligned with remote - $branchStatusSymbol = $s.BranchIdenticalStatusToSymbol + $branchStatusText = $s.BranchIdenticalStatusToSymbol $branchStatusBackgroundColor = $s.BranchIdenticalStatusToBackgroundColor $branchStatusForegroundColor = $s.BranchIdenticalStatusToForegroundColor } elseif ($status.BehindBy -ge 1 -and $status.AheadBy -ge 1) { # We are both behind and ahead of remote - $branchStatusSymbol = $s.BranchBehindAndAheadStatusSymbol + if ($s.BranchBehindAndAheadDisplay -eq "Full") { + $branchStatusText = ("{0}{1} {2}{3}" -f $s.BranchBehindStatusSymbol, $status.BehindBy, $s.BranchAheadStatusSymbol, $status.AheadBy) + } elseif ($s.BranchBehindAndAheadDisplay -eq "Compact") { + $branchStatusText = ("{0}{1}{2}" -f $status.BehindBy, $s.BranchBehindAndAheadStatusSymbol, $status.AheadBy) + } else { + $branchStatusText = $s.BranchBehindAndAheadStatusSymbol + } $branchStatusBackgroundColor = $s.BranchBehindAndAheadStatusBackgroundColor $branchStatusForegroundColor = $s.BranchBehindAndAheadStatusForegroundColor } elseif ($status.BehindBy -ge 1) { # We are behind remote - $branchStatusSymbol = $s.BranchBehindStatusSymbol + if ($s.BranchBehindAndAheadDisplay -eq "Full" -Or $s.BranchBehindAndAheadDisplay -eq "Compact") { + $branchStatusText = ("{0}{1}" -f $s.BranchBehindStatusSymbol, $status.BehindBy) + } else { + $branchStatusText = $s.BranchBehindStatusSymbol + } $branchStatusBackgroundColor = $s.BranchBehindStatusBackgroundColor $branchStatusForegroundColor = $s.BranchBehindStatusForegroundColor } elseif ($status.AheadBy -ge 1) { # We are ahead of remote - $branchStatusSymbol = $s.BranchAheadStatusSymbol + if ($s.BranchBehindAndAheadDisplay -eq "Full" -Or $s.BranchBehindAndAheadDisplay -eq "Compact") { + $branchStatusText = ("{0}{1}" -f $s.BranchAheadStatusSymbol, $status.AheadBy) + } else { + $branchStatusText = $s.BranchAheadStatusSymbol + } $branchStatusBackgroundColor = $s.BranchAheadStatusBackgroundColor $branchStatusForegroundColor = $s.BranchAheadStatusForegroundColor } else { # This condition should not be possible but defaulting the variables to be safe - $branchStatusSymbol = "?" + $branchStatusText = "?" } Write-Prompt (Format-BranchName($status.Branch)) -BackgroundColor $branchStatusBackgroundColor -ForegroundColor $branchStatusForegroundColor - if ($branchStatusSymbol) { - Write-Prompt (" {0}" -f $branchStatusSymbol) -BackgroundColor $branchStatusBackgroundColor -ForegroundColor $branchStatusForegroundColor + if ($branchStatusText) { + Write-Prompt (" {0}" -f $branchStatusText) -BackgroundColor $branchStatusBackgroundColor -ForegroundColor $branchStatusForegroundColor } if($s.EnableFileStatus -and $status.HasIndex) { diff --git a/profile.example.ps1 b/profile.example.ps1 index 84b17c2ab..c0442ee4f 100644 --- a/profile.example.ps1 +++ b/profile.example.ps1 @@ -20,6 +20,10 @@ function global:prompt { return "> " } +# Settings for the prompt are in GitPrompt.ps1, so add any desired settings changes here. +# Example: +# $Global:GitPromptSettings.BranchBehindAndAheadDisplayType = "Compact" + Pop-Location Start-SshAgent -Quiet From 830fe563c2285c8a9ba930ad5dcb16b3c3d2f910 Mon Sep 17 00:00:00 2001 From: Alan Bridgewater Date: Tue, 23 Feb 2016 11:12:30 -0800 Subject: [PATCH 2/3] Update profile sample to correct variable name --- profile.example.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/profile.example.ps1 b/profile.example.ps1 index c0442ee4f..bd9de33a1 100644 --- a/profile.example.ps1 +++ b/profile.example.ps1 @@ -22,7 +22,7 @@ function global:prompt { # Settings for the prompt are in GitPrompt.ps1, so add any desired settings changes here. # Example: -# $Global:GitPromptSettings.BranchBehindAndAheadDisplayType = "Compact" +# $Global:GitPromptSettings.BranchBehindAndAheadDisplay = "Compact" Pop-Location From 85ab3d7016a080c1927443524b4e3044eb9e588c Mon Sep 17 00:00:00 2001 From: Alan Bridgewater Date: Thu, 29 Dec 2016 14:50:39 -0800 Subject: [PATCH 3/3] Fix trailing whitespace :) --- GitPrompt.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GitPrompt.ps1 b/GitPrompt.ps1 index 06706c16b..c3b3731d0 100644 --- a/GitPrompt.ps1 +++ b/GitPrompt.ps1 @@ -186,7 +186,7 @@ function Write-GitStatus($status) { } Write-Prompt (Format-BranchName($status.Branch)) -BackgroundColor $branchStatusBackgroundColor -ForegroundColor $branchStatusForegroundColor - + if ($branchStatusText) { Write-Prompt (" {0}" -f $branchStatusText) -BackgroundColor $branchStatusBackgroundColor -ForegroundColor $branchStatusForegroundColor }