Skip to content

Commit

Permalink
Merge pull request #6 from dahlbyk/master
Browse files Browse the repository at this point in the history
Merging latest
  • Loading branch information
paulmarsy committed May 22, 2015
2 parents 66200ac + 4d95124 commit f961b77
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
22 changes: 19 additions & 3 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 Expand Up @@ -156,7 +170,9 @@ if(!(Test-Path Variable:Global:VcsPromptStatuses)) {
function Global:Write-VcsStatus { $Global:VcsPromptStatuses | foreach { & $_ } }

# Add scriptblock that will execute for Write-VcsStatus
$Global:VcsPromptStatuses += {
$PoshGitVcsPrompt = {
$Global:GitStatus = Get-GitStatus
Write-GitStatus $GitStatus
}
$Global:VcsPromptStatuses += $PoshGitVcsPrompt
$ExecutionContext.SessionState.Module.OnRemove = { $Global:VcsPromptStatuses = $Global:VcsPromptStatuses | ? { $_ -ne $PoshGitVcsPrompt} }
6 changes: 6 additions & 0 deletions GitTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ function script:gitBranches($filter, $includeHEAD = $false) {
foreach { $prefix + $_ }
}

function script:gitTags($filter) {
git tag |
where { $_ -like "$filter*" }
}

function script:gitFeatures($filter, $command){
$featurePrefix = git config --local --get "gitflow.prefix.$command"
$branches = @(git branch --no-color | foreach { if($_ -match "^\*?\s*$featurePrefix(?<ref>.*)") { $matches['ref'] } })
Expand Down Expand Up @@ -281,6 +286,7 @@ function GitTabExpansion($lastBlock) {
# Handles git <cmd> <ref>
"^(?:checkout|cherry|cherry-pick|diff|difftool|log|merge|rebase|reflog\s+show|reset|revert|show).* (?<ref>\S*)$" {
gitBranches $matches['ref'] $true
gitTags $matches['ref']
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion GitUtils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function InDisabledRepository {
}

function Enable-GitColors {
$env:TERM = 'cygwin'
Write-Warning 'Enable-GitColors is Obsolete and will be removed in a future version of posh-git.'
}

function Get-AliasPattern($exe) {
Expand Down
5 changes: 0 additions & 5 deletions profile.example.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ Import-Module .\posh-git
function global:prompt {
$realLASTEXITCODE = $LASTEXITCODE

# Reset color, which can be messed up by Enable-GitColors
$Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor

Write-Host($pwd.ProviderPath) -nonewline

Write-VcsStatus
Expand All @@ -23,8 +20,6 @@ function global:prompt {
return "> "
}

Enable-GitColors

Pop-Location

Start-SshAgent -Quiet

0 comments on commit f961b77

Please sign in to comment.