mirror of
https://github.com/cmderdev/cmder.git
synced 2025-02-11 07:59:07 +08:00
Merge pull request #1280 from bdukes/patch-1
Allow profile.d/*.ps1 files to export [scriptblock]$prompt override all of cmders prompt
This commit is contained in:
commit
ad0f8fe049
58
vendor/profile.ps1
vendored
58
vendor/profile.ps1
vendored
@ -86,19 +86,6 @@ if (Get-Module PSReadline -ErrorAction "SilentlyContinue") {
|
|||||||
# Enhance Path
|
# Enhance Path
|
||||||
$env:Path = "$Env:CMDER_ROOT\bin;$env:Path;$Env:CMDER_ROOT"
|
$env:Path = "$Env:CMDER_ROOT\bin;$env:Path;$Env:CMDER_ROOT"
|
||||||
|
|
||||||
# Drop *.ps1 files into "$ENV:CMDER_ROOT\config\profile.d"
|
|
||||||
# to source them at startup.
|
|
||||||
if (-not (test-path "$ENV:CMDER_ROOT\config\profile.d")) {
|
|
||||||
mkdir "$ENV:CMDER_ROOT\config\profile.d"
|
|
||||||
}
|
|
||||||
|
|
||||||
pushd $ENV:CMDER_ROOT\config\profile.d
|
|
||||||
foreach ($x in ls *.ps1) {
|
|
||||||
# write-host write-host Sourcing $x
|
|
||||||
. $x
|
|
||||||
}
|
|
||||||
popd
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Prompt Section
|
# Prompt Section
|
||||||
# Users should modify their user-profile.ps1 as it will be safe from updates.
|
# Users should modify their user-profile.ps1 as it will be safe from updates.
|
||||||
@ -113,6 +100,35 @@ popd
|
|||||||
checkGit($pwd.ProviderPath)
|
checkGit($pwd.ProviderPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<#
|
||||||
|
This scriptblock runs every time the prompt is returned.
|
||||||
|
Explicitly use functions from MS namespace to protect from being overridden in the user session.
|
||||||
|
Custom prompt functions are loaded in as constants to get the same behaviour
|
||||||
|
#>
|
||||||
|
[ScriptBlock]$Prompt = {
|
||||||
|
$realLASTEXITCODE = $LASTEXITCODE
|
||||||
|
$host.UI.RawUI.WindowTitle = Microsoft.PowerShell.Management\Split-Path $pwd.ProviderPath -Leaf
|
||||||
|
PrePrompt | Microsoft.PowerShell.Utility\Write-Host -NoNewline
|
||||||
|
CmderPrompt
|
||||||
|
Microsoft.PowerShell.Utility\Write-Host "`nλ " -NoNewLine -ForegroundColor "DarkGray"
|
||||||
|
PostPrompt | Microsoft.PowerShell.Utility\Write-Host -NoNewline
|
||||||
|
$global:LASTEXITCODE = $realLASTEXITCODE
|
||||||
|
return " "
|
||||||
|
}
|
||||||
|
|
||||||
|
# Drop *.ps1 files into "$ENV:CMDER_ROOT\config\profile.d"
|
||||||
|
# to source them at startup.
|
||||||
|
if (-not (test-path "$ENV:CMDER_ROOT\config\profile.d")) {
|
||||||
|
mkdir "$ENV:CMDER_ROOT\config\profile.d"
|
||||||
|
}
|
||||||
|
|
||||||
|
pushd $ENV:CMDER_ROOT\config\profile.d
|
||||||
|
foreach ($x in ls *.ps1) {
|
||||||
|
# write-host write-host Sourcing $x
|
||||||
|
. $x
|
||||||
|
}
|
||||||
|
popd
|
||||||
|
|
||||||
$CmderUserProfilePath = Join-Path $env:CMDER_ROOT "config\user-profile.ps1"
|
$CmderUserProfilePath = Join-Path $env:CMDER_ROOT "config\user-profile.ps1"
|
||||||
if(Test-Path $CmderUserProfilePath) {
|
if(Test-Path $CmderUserProfilePath) {
|
||||||
# Create this file and place your own command in there.
|
# Create this file and place your own command in there.
|
||||||
@ -160,22 +176,6 @@ Set-Item -Path function:\PrePrompt -Value $PrePrompt -Options Constant
|
|||||||
Set-Item -Path function:\CmderPrompt -Value $CmderPrompt -Options Constant
|
Set-Item -Path function:\CmderPrompt -Value $CmderPrompt -Options Constant
|
||||||
Set-Item -Path function:\PostPrompt -Value $PostPrompt -Options Constant
|
Set-Item -Path function:\PostPrompt -Value $PostPrompt -Options Constant
|
||||||
|
|
||||||
<#
|
|
||||||
This scriptblock runs every time the prompt is returned.
|
|
||||||
Explicitly use functions from MS namespace to protect from being overridden in the user session.
|
|
||||||
Custom prompt functions are loaded in as constants to get the same behaviour
|
|
||||||
#>
|
|
||||||
[ScriptBlock]$Prompt = {
|
|
||||||
$realLASTEXITCODE = $LASTEXITCODE
|
|
||||||
$host.UI.RawUI.WindowTitle = Microsoft.PowerShell.Management\Split-Path $pwd.ProviderPath -Leaf
|
|
||||||
PrePrompt | Microsoft.PowerShell.Utility\Write-Host -NoNewline
|
|
||||||
CmderPrompt
|
|
||||||
Microsoft.PowerShell.Utility\Write-Host "`nλ " -NoNewLine -ForegroundColor "DarkGray"
|
|
||||||
PostPrompt | Microsoft.PowerShell.Utility\Write-Host -NoNewline
|
|
||||||
$global:LASTEXITCODE = $realLASTEXITCODE
|
|
||||||
return " "
|
|
||||||
}
|
|
||||||
|
|
||||||
# Functions can be made constant only at creation time
|
# Functions can be made constant only at creation time
|
||||||
# ReadOnly at least requires `-force` to be overwritten
|
# ReadOnly at least requires `-force` to be overwritten
|
||||||
Set-Item -Path function:\prompt -Value $Prompt -Options ReadOnly
|
Set-Item -Path function:\prompt -Value $Prompt -Options ReadOnly
|
||||||
|
Loading…
x
Reference in New Issue
Block a user