Permalink
Browse files

Merge pull request #371 from dahlbyk/rkeithhill/enable-default-prompt…

…-timing

Worth adding optional timing output to def prompt?
2 parents 5875645 + 3b7971d commit 73b8bf9c588df6d17c193e270da0ed4cf890d868 @dahlbyk committed on GitHub Jan 17, 2017
Showing with 17 additions and 4 deletions.
  1. +3 −2 GitPrompt.ps1
  2. +14 −2 posh-git.psm1
View
@@ -97,8 +97,9 @@ $global:GitPromptSettings = New-Object PSObject -Property @{
EnableWindowTitle = 'posh~git ~ '
- PromptSuffix = '$(''>'' * ($nestedPromptLevel + 1)) '
- PromptDebugSuffix = ' [DBG]$(''>'' * ($nestedPromptLevel + 1)) '
+ DefaultPromptSuffix = '$(''>'' * ($nestedPromptLevel + 1)) '
+ DefaultPromptDebugSuffix = ' [DBG]$(''>'' * ($nestedPromptLevel + 1)) '
+ DefaultPromptEnableTiming = $false
Debug = $false
View
@@ -45,6 +45,9 @@ if (!$currentPromptDef) {
if (!$currentPromptDef -or ($currentPromptDef -eq $defaultPromptDef)) {
# Have to use [scriptblock]::Create() to get debugger detection to work in PS v2
$poshGitPromptScriptBlock = [scriptblock]::Create(@'
+ if ($GitPromptSettings.DefaultPromptEnableTiming) {
+ $sw = [System.Diagnostics.Stopwatch]::StartNew()
+ }
$origLastExitCode = $global:LASTEXITCODE
# A UNC path has no drive so it's better to use the ProviderPath e.g. "\\server\share".
@@ -76,15 +79,24 @@ if (!$currentPromptDef -or ($currentPromptDef -eq $defaultPromptDef)) {
# If stopped in the debugger, the prompt needs to indicate that in some fashion
$debugMode = (Test-Path Variable:/PSDebugContext) -or [runspace]::DefaultRunspace.Debugger.InBreakpoint
- $promptSuffix = if ($debugMode) { $GitPromptSettings.PromptDebugSuffix } else { $GitPromptSettings.PromptSuffix }
+ $promptSuffix = if ($debugMode) { $GitPromptSettings.DefaultPromptDebugSuffix } else { $GitPromptSettings.DefaultPromptSuffix }
# If user specifies $null or empty string, set to ' ' to avoid "PS>" unexpectedly being displayed
if (!$promptSuffix) {
$promptSuffix = ' '
}
+ $expandedPromptSuffix = $ExecutionContext.SessionState.InvokeCommand.ExpandString($promptSuffix)
+
+ # If prompt timing enabled, display elapsed milliseconds
+ if ($GitPromptSettings.DefaultPromptEnableTiming) {
+ $sw.Stop()
+ $elapsed = $sw.ElapsedMilliseconds
+ Write-Host " ${elapsed}ms" -NoNewline
+ }
+
$global:LASTEXITCODE = $origLastExitCode
- $ExecutionContext.SessionState.InvokeCommand.ExpandString($promptSuffix)
+ $expandedPromptSuffix
'@)
# Set the posh-git prompt as the default prompt

0 comments on commit 73b8bf9

Please sign in to comment.