Skip to content

Commit

Permalink
Merge pull request #277 from 9999years/promptVariables
Browse files Browse the repository at this point in the history
Added variables to make customizing the prompt easier.
  • Loading branch information
dahlbyk committed May 6, 2016
2 parents 6bd5770 + 59069a5 commit 2faae5d
Showing 1 changed file with 33 additions and 28 deletions.
61 changes: 33 additions & 28 deletions GitPrompt.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ $global:GitPromptSettings = New-Object PSObject -Property @{
BeforeText = ' ['
BeforeForegroundColor = [ConsoleColor]::Yellow
BeforeBackgroundColor = $Host.UI.RawUI.BackgroundColor

DelimText = ' |'
DelimForegroundColor = [ConsoleColor]::Yellow
DelimBackgroundColor = $Host.UI.RawUI.BackgroundColor
Expand All @@ -16,16 +16,21 @@ $global:GitPromptSettings = New-Object PSObject -Property @{
AfterForegroundColor = [ConsoleColor]::Yellow
AfterBackgroundColor = $Host.UI.RawUI.BackgroundColor

FileAddedText = '+'
FileModifiedText = '~'
FileRemovedText = '-'
FileConflictedText = '!'

LocalDefaultStatusSymbol = $null
LocalDefaultStatusForegroundColor = [ConsoleColor]::DarkGreen
LocalDefaultStatusForegroundBrightColor = [ConsoleColor]::Green
LocalDefaultStatusBackgroundColor = $Host.UI.RawUI.BackgroundColor

LocalWorkingStatusSymbol = '!'
LocalWorkingStatusForegroundColor = [ConsoleColor]::DarkRed
LocalWorkingStatusForegroundBrightColor = [ConsoleColor]::Red
LocalWorkingStatusBackgroundColor = $Host.UI.RawUI.BackgroundColor

LocalStagedStatusSymbol = '~'
LocalStagedStatusForegroundColor = [ConsoleColor]::Cyan
LocalStagedStatusBackgroundColor = $Host.UI.RawUI.BackgroundColor
Expand All @@ -37,15 +42,15 @@ $global:GitPromptSettings = New-Object PSObject -Property @{
BranchIdenticalStatusToSymbol = [char]0x2261 # Three horizontal lines
BranchIdenticalStatusToForegroundColor = [ConsoleColor]::Cyan
BranchIdenticalStatusToBackgroundColor = $Host.UI.RawUI.BackgroundColor

BranchAheadStatusSymbol = [char]0x2191 # Up arrow
BranchAheadStatusForegroundColor = [ConsoleColor]::Green
BranchAheadStatusBackgroundColor = $Host.UI.RawUI.BackgroundColor

BranchBehindStatusSymbol = [char]0x2193 # Down arrow
BranchBehindStatusForegroundColor = [ConsoleColor]::Red
BranchBehindStatusBackgroundColor = $Host.UI.RawUI.BackgroundColor

BranchBehindAndAheadStatusSymbol = [char]0x2195 # Up & Down arrow
BranchBehindAndAheadStatusForegroundColor = [ConsoleColor]::Yellow
BranchBehindAndAheadStatusBackgroundColor = $Host.UI.RawUI.BackgroundColor
Expand All @@ -63,15 +68,15 @@ $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

Expand Down Expand Up @@ -156,7 +161,7 @@ function Write-GitStatus($status) {
}

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

if ($branchStatusSymbol) {
Write-Prompt (" {0}" -f $branchStatusSymbol) -BackgroundColor $branchStatusBackgroundColor -ForegroundColor $branchStatusForegroundColor
}
Expand All @@ -165,17 +170,17 @@ function Write-GitStatus($status) {
Write-Prompt $s.BeforeIndexText -BackgroundColor $s.BeforeIndexBackgroundColor -ForegroundColor $s.BeforeIndexForegroundColor

if($s.ShowStatusWhenZero -or $status.Index.Added) {
Write-Prompt " +$($status.Index.Added.Count)" -BackgroundColor $s.IndexBackgroundColor -ForegroundColor $s.IndexForegroundColor
Write-Prompt (" $($s.FileAddedText)$($status.Index.Added.Count)") -BackgroundColor $s.IndexBackgroundColor -ForegroundColor $s.IndexForegroundColor
}
if($s.ShowStatusWhenZero -or $status.Index.Modified) {
Write-Prompt " ~$($status.Index.Modified.Count)" -BackgroundColor $s.IndexBackgroundColor -ForegroundColor $s.IndexForegroundColor
Write-Prompt (" $($s.FileModifiedText)$($status.Index.Modified.Count)") -BackgroundColor $s.IndexBackgroundColor -ForegroundColor $s.IndexForegroundColor
}
if($s.ShowStatusWhenZero -or $status.Index.Deleted) {
Write-Prompt " -$($status.Index.Deleted.Count)" -BackgroundColor $s.IndexBackgroundColor -ForegroundColor $s.IndexForegroundColor
Write-Prompt (" $($s.FileRemovedText)$($status.Index.Deleted.Count)") -BackgroundColor $s.IndexBackgroundColor -ForegroundColor $s.IndexForegroundColor
}

if ($status.Index.Unmerged) {
Write-Prompt " !$($status.Index.Unmerged.Count)" -BackgroundColor $s.IndexBackgroundColor -ForegroundColor $s.IndexForegroundColor
Write-Prompt (" $($s.FileConflictedText)$($status.Index.Unmerged.Count)") -BackgroundColor $s.IndexBackgroundColor -ForegroundColor $s.IndexForegroundColor
}

if($status.HasWorking) {
Expand All @@ -185,17 +190,17 @@ function Write-GitStatus($status) {

if($s.EnableFileStatus -and $status.HasWorking) {
if($s.ShowStatusWhenZero -or $status.Working.Added) {
Write-Prompt " +$($status.Working.Added.Count)" -BackgroundColor $s.WorkingBackgroundColor -ForegroundColor $s.WorkingForegroundColor
Write-Prompt (" $($s.FileAddedText)$($status.Working.Added.Count)") -BackgroundColor $s.WorkingBackgroundColor -ForegroundColor $s.WorkingForegroundColor
}
if($s.ShowStatusWhenZero -or $status.Working.Modified) {
Write-Prompt " ~$($status.Working.Modified.Count)" -BackgroundColor $s.WorkingBackgroundColor -ForegroundColor $s.WorkingForegroundColor
Write-Prompt (" $($s.FileModifiedText)$($status.Working.Modified.Count)") -BackgroundColor $s.WorkingBackgroundColor -ForegroundColor $s.WorkingForegroundColor
}
if($s.ShowStatusWhenZero -or $status.Working.Deleted) {
Write-Prompt " -$($status.Working.Deleted.Count)" -BackgroundColor $s.WorkingBackgroundColor -ForegroundColor $s.WorkingForegroundColor
Write-Prompt (" $($s.FileRemovedText)$($status.Working.Deleted.Count)") -BackgroundColor $s.WorkingBackgroundColor -ForegroundColor $s.WorkingForegroundColor
}

if ($status.Working.Unmerged) {
Write-Prompt " !$($status.Working.Unmerged.Count)" -BackgroundColor $s.WorkingBackgroundColor -ForegroundColor $s.WorkingForegroundColor
Write-Prompt (" $($s.FileConflictedText)$($status.Working.Unmerged.Count)") -BackgroundColor $s.WorkingBackgroundColor -ForegroundColor $s.WorkingForegroundColor
}
}

Expand All @@ -215,11 +220,11 @@ function Write-GitStatus($status) {
$localStatusBackgroundColor = $s.LocalDefaultStatusBackgroundColor
$localStatusForegroundColor = $s.LocalDefaultStatusForegroundColor
}

if ($localStatusSymbol) {
Write-Prompt (" {0}" -f $localStatusSymbol) -BackgroundColor $localStatusBackgroundColor -ForegroundColor $localStatusForegroundColor
}

if ($s.EnableStashStatus -and ($status.StashCount -gt 0)) {
Write-Prompt $s.BeforeStashText -BackgroundColor $s.BeforeStashBackgroundColor -ForegroundColor $s.BeforeStashForegroundColor
Write-Prompt $status.StashCount -BackgroundColor $s.StashBackgroundColor -ForegroundColor $s.StashForegroundColor
Expand Down Expand Up @@ -250,7 +255,7 @@ $s = $global:GitPromptSettings
if ($Host.UI.RawUI.BackgroundColor -eq [ConsoleColor]::DarkMagenta) {
$s.LocalDefaultStatusForegroundColor = $s.LocalDefaultStatusForegroundBrightColor
$s.LocalWorkingStatusForegroundColor = $s.LocalWorkingStatusForegroundBrightColor

$s.BeforeIndexForegroundColor = $s.BeforeIndexForegroundBrightColor
$s.IndexForegroundColor = $s.IndexForegroundBrightColor

Expand All @@ -265,4 +270,4 @@ $PoshGitVcsPrompt = {
Write-GitStatus $GitStatus
}
$Global:VcsPromptStatuses += $PoshGitVcsPrompt
$ExecutionContext.SessionState.Module.OnRemove = { $Global:VcsPromptStatuses = $Global:VcsPromptStatuses | ? { $_ -ne $PoshGitVcsPrompt} }
$ExecutionContext.SessionState.Module.OnRemove = { $Global:VcsPromptStatuses = $Global:VcsPromptStatuses | ? { $_ -ne $PoshGitVcsPrompt} }

0 comments on commit 2faae5d

Please sign in to comment.