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

Bust up Write-GitStatus into smaller functions to make it easier for individuals to override parts of the status display #345

Closed
rkeithhill opened this issue Dec 31, 2016 · 3 comments

Comments

@rkeithhill
Copy link
Collaborator

rkeithhill commented Dec 31, 2016

I see a number of PRs come across to change the Git status summary display for things that probably don't apply to that many folks. And folks can today write their own prompt function to take the information from Get-GitStatus to display the Git status summary, plus any additional information in anyway they would like. However, in many cases folks just want to tweak one area of the Git status summary info. With this in mind, we should break up the bits and pieces of Write-GitStatus into reusable functions.

Perhaps we have Write-GitStatus call down to Write-BranchStatus, Write-GitIndexStatus, and Write-GitWorkingDirStatus.

In one PR scenario the OP wants to display any tags associated with HEAD. In this case, the OP could create his own version of Write-BranchStatus to display tags. Then in his prompt function he could call Write-GitIndexStatus and Write-GitWorkingDirStatus to create the rest of the status summary text. This would make overriding an individual status summary section much easier.

You could make the functions even finer grained as well. Perhaps break down Write-BranchStatus into Write-BranchName and Write-BranchSyncStatus?

@dahlbyk
Copy link
Owner

dahlbyk commented Jan 1, 2017

This is also related to #304 and Jaykul/PowerLine#1. More modularity and customizability in how the prompt displays would be awesome. And if we do it right, it seems like an opportunity to remove a bunch of clutter from $GitPromptSettings, e.g. default might be:

function Write-GitStatus ($GitStatus) {
  Write-Prompt ' [' -ForegroundColor Yellow # No need for Before settings
  Write-GitBranchStatus $GitStatus
  Write-GitFileStatus $GitStatus
  Write-GitLocalStatus $GitStatus
  Write-Prompt ']' -ForegroundColor Yellow # No need for After settings
}

And to customize:

function Write-GitStatus ($GitStatus) {
  Write-Prompt ' {'
  Write-GitBranchStatus $GitStatus -AheadBehindDisplay Compact -GoneText ''
  # No need for EnableFileStatus; just don't call Write-GitFileStatus
  Write-GitLocalStatus -StagedText ''
  Write-GitStashStatus -Before ' (' -After '(' -ForegroundColor Red
  Write-Prompt '}'
}

@rkeithhill
Copy link
Collaborator Author

rkeithhill commented Oct 30, 2017

I've implemented this on branch - https://github.com/dahlbyk/posh-git/tree/rkeithhill/refactor-write-prompt This branch is a branch off of the settings-only-update branch.

At the moment, each of the broken up Write-* functions internally uses $GitPromptSettings. This is primarily for it know the symbol and colors to use. That said, we could update these functions to take that information. So currently your function would look like:

$global:GitPromptSettings.BranchBehindAndAheadDisplay = 'Compact'
$global:GitPromptSettngs.StashColor.ForegroundColor = 'Red'
$global:GitPromptSettngs.BeforeStashText.ForegroundColor = 'Red'
$global:GitPromptSettngs.AfterStashText.ForegroundColor = 'Red'

function Write-MyGitStatus ($GitStatus) {
  Write-Prompt ' {'
  Write-GitBranchStatus $GitStatus
  Write-GitWorkingDirStatus $GitStatus
  Write-Prompt ' ('
  Write-GitStashCount $GitStatus
  Write-Prompt ')}'
}

BTW should we use Write-GitLocalStatus instead of Write-GitWorkingDirStatus? Of course, what do I for Write-GitWorkingDirLocalStatus? Write-GitLocalLocalStatus would be a bit weird. :-)

@rkeithhill
Copy link
Collaborator Author

Fixed via PR #513

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants