Skip to content
Browse files

Allow custom scripts to be executed in prompt

New settings:
* $GitPromptSettings.BeforeScript
* $GitPromptSettings.AfterBranchScript
* $GitPromptSettings.AfterScript

Usage:

$GitPromptSettings.BeforeScript = {
    param($status, $backgroundColor, $foregroundColor)
    Write-Prompt "<" -BackgroundColor $backgroundColor -ForegroundColor $foregroundColor
    Write-Prompt "$(git config user.email)" -ForegroundColor White
    Write-Prompt "> " -BackgroundColor $backgroundColor -ForegroundColor $foregroundColor
}
  • Loading branch information...
1 parent ac4e529 commit 53ece22dd4fced672c9c060f8935f344957b7ad8 @dahlbyk committed Oct 26, 2012
Showing with 15 additions and 0 deletions.
  1. +15 −0 GitPrompt.ps1
View
15 GitPrompt.ps1
@@ -7,13 +7,16 @@ $global:GitPromptSettings = New-Object PSObject -Property @{
BeforeText = ' ['
BeforeForegroundColor = [ConsoleColor]::Yellow
BeforeBackgroundColor = $Host.UI.RawUI.BackgroundColor
+ BeforeScript = $null
+
DelimText = ' |'
DelimForegroundColor = [ConsoleColor]::Yellow
DelimBackgroundColor = $Host.UI.RawUI.BackgroundColor
AfterText = ']'
AfterForegroundColor = [ConsoleColor]::Yellow
AfterBackgroundColor = $Host.UI.RawUI.BackgroundColor
+ AfterScript = $null
BranchForegroundColor = [ConsoleColor]::Cyan
BranchBackgroundColor = $Host.UI.RawUI.BackgroundColor
@@ -24,6 +27,8 @@ $global:GitPromptSettings = New-Object PSObject -Property @{
BranchBehindAndAheadForegroundColor = [ConsoleColor]::Yellow
BranchBehindAndAheadBackgroundColor = $Host.UI.RawUI.BackgroundColor
+ AfterBranchScript = $null
+
BeforeIndexText = ""
BeforeIndexForegroundColor= [ConsoleColor]::DarkGreen
BeforeIndexBackgroundColor= $Host.UI.RawUI.BackgroundColor
@@ -61,6 +66,9 @@ function Write-GitStatus($status) {
$s = $global:GitPromptSettings
if ($status -and $s) {
Write-Prompt $s.BeforeText -BackgroundColor $s.BeforeBackgroundColor -ForegroundColor $s.BeforeForegroundColor
+ if ($s.BeforeScript -is [ScriptBlock]) {
+ Invoke-Command $s.BeforeScript -NoNewScope -ArgumentList $status,$s.BeforeBackgroundColor,$s.BeforeForegroundColor
+ }
$branchBackgroundColor = $s.BranchBackgroundColor
$branchForegroundColor = $s.BranchForegroundColor
@@ -79,6 +87,9 @@ function Write-GitStatus($status) {
}
Write-Prompt $status.Branch -BackgroundColor $branchBackgroundColor -ForegroundColor $branchForegroundColor
+ if ($s.AfterBranchScript -is [ScriptBlock]) {
+ Invoke-Command $s.AfterBranchScript -NoNewScope -ArgumentList $status,$branchBackgroundColor,$branchForegroundColor
+ }
if($s.EnableFileStatus -and $status.HasIndex) {
Write-Prompt $s.BeforeIndexText -BackgroundColor $s.BeforeIndexBackgroundColor -ForegroundColor $s.BeforeIndexForegroundColor
@@ -122,6 +133,10 @@ function Write-GitStatus($status) {
Write-Prompt $s.UntrackedText -BackgroundColor $s.UntrackedBackgroundColor -ForegroundColor $s.UntrackedForegroundColor
}
+ if ($s.AfterScript -is [ScriptBlock]) {
+ Invoke-Command $s.AfterScript -NoNewScope -ArgumentList $status,$s.AfterBackgroundColor,$s.AfterForegroundColor
+ }
+
Write-Prompt $s.AfterText -BackgroundColor $s.AfterBackgroundColor -ForegroundColor $s.AfterForegroundColor
}
}

0 comments on commit 53ece22

Please sign in to comment.
Something went wrong with that request. Please try again.