Skip to content

Commit

Permalink
Merge pull request #139 from dbuckingham/limit-branch-name-length
Browse files Browse the repository at this point in the history
Limit length of long branch name
  • Loading branch information
dahlbyk committed May 22, 2015
2 parents 5947ce7 + 026e236 commit 4d95124
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions GitPrompt.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

$global:GitPromptSettings = New-Object PSObject -Property @{
DefaultForegroundColor = $Host.UI.RawUI.ForegroundColor

BeforeText = ' ['
BeforeForegroundColor = [ConsoleColor]::Yellow
BeforeBackgroundColor = $Host.UI.RawUI.BackgroundColor
Expand Down Expand Up @@ -50,6 +50,9 @@ $global:GitPromptSettings = New-Object PSObject -Property @{
EnableWindowTitle = 'posh~git ~ '

Debug = $false

BranchNameLimit = 0
TruncatedBranchSuffix = '...'
}

$currentUser = [Security.Principal.WindowsPrincipal]([Security.Principal.WindowsIdentity]::GetCurrent())
Expand All @@ -70,6 +73,17 @@ function Write-Prompt($Object, $ForegroundColor, $BackgroundColor = -1) {
}
}

function Format-BranchName($branchName){
$s = $global:GitPromptSettings

if($s.BranchNameLimit -gt 0 -and $branchName.Length -gt $s.BranchNameLimit)
{
$branchName = "{0}{1}" -f $branchName.Substring(0,$s.BranchNameLimit), $s.TruncatedBranchSuffix
}

return $branchName
}

function Write-GitStatus($status) {
$s = $global:GitPromptSettings
if ($status -and $s) {
Expand All @@ -91,7 +105,7 @@ function Write-GitStatus($status) {
$branchForegroundColor = $s.BranchAheadForegroundColor
}

Write-Prompt $status.Branch -BackgroundColor $branchBackgroundColor -ForegroundColor $branchForegroundColor
Write-Prompt (Format-BranchName($status.Branch)) -BackgroundColor $branchBackgroundColor -ForegroundColor $branchForegroundColor

if($s.EnableFileStatus -and $status.HasIndex) {
Write-Prompt $s.BeforeIndexText -BackgroundColor $s.BeforeIndexBackgroundColor -ForegroundColor $s.BeforeIndexForegroundColor
Expand Down

0 comments on commit 4d95124

Please sign in to comment.