From b349b1986927d3c2c0dae2c6c17ec4964042177a Mon Sep 17 00:00:00 2001 From: Jackbennett Date: Mon, 10 Oct 2016 10:30:01 +0100 Subject: [PATCH] Describe why PS functions are called by namespace As the prompt function is called all the time, specifically namespace the cmldets it uses to avoid them being hijacked in the user session. --- vendor/profile.ps1 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/vendor/profile.ps1 b/vendor/profile.ps1 index 0394209..fc0f324 100644 --- a/vendor/profile.ps1 +++ b/vendor/profile.ps1 @@ -155,9 +155,14 @@ Set-Item -Path function:\PrePrompt -Value $PrePrompt -Options Constant Set-Item -Path function:\CmderPrompt -Value $CmderPrompt -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 = Split-Path $pwd.ProviderPath -Leaf + $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" @@ -166,5 +171,6 @@ Set-Item -Path function:\PostPrompt -Value $PostPrompt -Options Constant return " " } +# Functions can be made constant only at creation time # ReadOnly at least requires `-force` to be overwritten Set-Item -Path function:\prompt -Value $Prompt -Options ReadOnly