Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Worth adding optional timing output to def prompt? #371

Merged
merged 3 commits into from
Jan 17, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions GitPrompt.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 14 additions & 2 deletions posh-git.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down Expand Up @@ -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
Copy link
Collaborator Author

@rkeithhill rkeithhill Jan 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me. You can simplify that a bit " ${elapsed}ms". In interpolated strings in PowerShell, you can delineate variable names from other text with ${<variable-name>}.

}

$global:LASTEXITCODE = $origLastExitCode
$ExecutionContext.SessionState.InvokeCommand.ExpandString($promptSuffix)
$expandedPromptSuffix
'@)

# Set the posh-git prompt as the default prompt
Expand Down