Fix #2192: Set default prompt hooks before loading user profile

This commit is contained in:
Greg Lucas 2019-10-22 11:17:13 -04:00
parent 3736508b2c
commit 7f69f15637

25
vendor/profile.ps1 vendored
View File

@ -44,7 +44,7 @@ function Configure-Git($GIT_INSTALL_ROOT){
if ((test-path "$GIT_INSTALL_ROOT\usr\bin") -and -not ($env:path -match "$GIT_INSTALL_ROOT_ESC\\usr\\bin")) { if ((test-path "$GIT_INSTALL_ROOT\usr\bin") -and -not ($env:path -match "$GIT_INSTALL_ROOT_ESC\\usr\\bin")) {
$env:path = "$env:path;$GIT_INSTALL_ROOT\usr\bin" $env:path = "$env:path;$GIT_INSTALL_ROOT\usr\bin"
} }
# Add "$GIT_INSTALL_ROOT\mingw[32|64]\bin" to the path if exists and not done already # Add "$GIT_INSTALL_ROOT\mingw[32|64]\bin" to the path if exists and not done already
if ((test-path "$GIT_INSTALL_ROOT\mingw32\bin") -and -not ($env:path -match "$GIT_INSTALL_ROOT_ESC\\mingw32\\bin")) { if ((test-path "$GIT_INSTALL_ROOT\mingw32\bin") -and -not ($env:path -match "$GIT_INSTALL_ROOT_ESC\\mingw32\\bin")) {
$env:path = "$env:path;$GIT_INSTALL_ROOT\mingw32\bin" $env:path = "$env:path;$GIT_INSTALL_ROOT\mingw32\bin"
@ -96,6 +96,18 @@ if (Get-Module PSReadline -ErrorAction "SilentlyContinue") {
Set-PSReadlineOption -ExtraPromptLineCount 1 Set-PSReadlineOption -ExtraPromptLineCount 1
} }
# Pre assign default prompt hooks so the first run of cmder gets a working prompt.
[ScriptBlock]$PrePrompt = {}
[ScriptBlock]$PostPrompt = {}
[ScriptBlock]$CmderPrompt = {
$Host.UI.RawUI.ForegroundColor = "White"
Write-Host -NoNewline "$([char]0x200B)"
Microsoft.PowerShell.Utility\Write-Host $pwd.ProviderPath -NoNewLine -ForegroundColor Green
if (get-command git -erroraction silentlycontinue) {
checkGit($pwd.ProviderPath)
}
}
# Enhance Path # Enhance Path
$env:Path = "$Env:CMDER_ROOT\bin;$Env:CMDER_ROOT\vendor\bin;$env:Path;$Env:CMDER_ROOT" $env:Path = "$Env:CMDER_ROOT\bin;$Env:CMDER_ROOT\vendor\bin;$env:Path;$Env:CMDER_ROOT"
@ -172,17 +184,6 @@ if (! (Test-Path $CmderUserProfilePath) ) {
# This allows users to configure the prompt in their user_profile.ps1 or config\profile.d\*.ps1 # This allows users to configure the prompt in their user_profile.ps1 or config\profile.d\*.ps1
if ( $(get-command prompt).Definition -match 'PS \$\(\$executionContext.SessionState.Path.CurrentLocation\)\$\(' -and ` if ( $(get-command prompt).Definition -match 'PS \$\(\$executionContext.SessionState.Path.CurrentLocation\)\$\(' -and `
$(get-command prompt).Definition -match '\(\$nestedPromptLevel \+ 1\)\) ";') { $(get-command prompt).Definition -match '\(\$nestedPromptLevel \+ 1\)\) ";') {
# Pre assign the hooks so the first run of cmder gets a working prompt.
[ScriptBlock]$PrePrompt = {}
[ScriptBlock]$PostPrompt = {}
[ScriptBlock]$CmderPrompt = {
$Host.UI.RawUI.ForegroundColor = "White"
Write-Host -NoNewline "$([char]0x200B)"
Microsoft.PowerShell.Utility\Write-Host $pwd.ProviderPath -NoNewLine -ForegroundColor Green
if (get-command git -erroraction silentlycontinue) {
checkGit($pwd.ProviderPath)
}
}
<# <#
This scriptblock runs every time the prompt is returned. This scriptblock runs every time the prompt is returned.