-
-
Notifications
You must be signed in to change notification settings - Fork 811
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
Show AheadyBy/BehindBy counts based on configuration #256
Changes from all commits
6babbc4
830fe56
7fb166a
85ab3d7
b443b40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,8 +74,8 @@ $global:GitPromptSettings = New-Object PSObject -Property @{ | |
|
||
EnableStashStatus = $false | ||
BeforeStashText = ' (' | ||
BeforeStashBackgroundColor = $Host.UI.RawUI.BackgroundColor | ||
BeforeStashForegroundColor = [ConsoleColor]::Red | ||
BeforeStashBackgroundColor = $Host.UI.RawUI.BackgroundColor | ||
BeforeStashForegroundColor = [ConsoleColor]::Red | ||
AfterStashText = ')' | ||
AfterStashBackgroundColor = $Host.UI.RawUI.BackgroundColor | ||
AfterStashForegroundColor = [ConsoleColor]::Red | ||
|
@@ -86,6 +86,9 @@ $global:GitPromptSettings = New-Object PSObject -Property @{ | |
|
||
AutoRefreshIndex = $true | ||
|
||
# Valid values are "Full", "Compact", and "Minimal" | ||
BranchBehindAndAheadDisplay = "Full" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about defaulting to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's exactly why I left it default to Full and then added the example showing how to make it Compact. I find that the staged files section takes way more space than the Full view, unless you're dealing with seriously out of sync branches. |
||
|
||
EnablePromptStatus = !$Global:GitMissing | ||
EnableFileStatus = $true | ||
RepositoriesInWhichToDisableFileStatus = @( ) # Array of repository paths | ||
|
@@ -141,46 +144,60 @@ 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.UpstreamGone -eq $true) { | ||
# Upstream branch is gone | ||
$branchStatusSymbol = $s.BranchGoneStatusSymbol | ||
$branchStatusText = $s.BranchGoneStatusSymbol | ||
$branchStatusBackgroundColor = $s.BranchGoneStatusBackgroundColor | ||
$branchStatusForegroundColor = $s.BranchGoneStatusForegroundColor | ||
} 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) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts on defining an enum to represent the valid states?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about it, but seemed like overkill to me, since nothing else uses enums yet, and the syntax for enums seems less Powershell-y than some weird hack. If enums were already used, I would have defined them that way. But I can add.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to use an enum but once we drop support on master for PS v2, you can use:
PS v2 support can't be dropped soon enough. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, that doesn't work because it's a set of properties being initialized, not a variable. We could move it outside the GitPromptSettings declaration as a special case, but that's kind of ugly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doh. Yeah, sometimes the narrow GitHub diff window bites me. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For 1.0 we could consider converting
$GitPromptSettings
to a giant config function of doom, as @Jaykul proposed long ago.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's an interesting approach. It does have the benefit of providing tab-completion/validation on each parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That change that was proposed has a side effect of having to pass the same parameters that you've already changed to the config method, since the default value for the parameter is a hard-coded defined value. You could still save the settings in a variable/property bag for storing, and perhaps have the default value for the parameter be the value already in the property bag, so that once changed, it will be used for subsequent sets.
Or you can do the Add-Type -TypeDefinition method to create enums you need and a class that has a bunch of public properties. They won't have tab-completion, but they will have parameter validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened #340 for discussion, targeting 1.0.