-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMicrosoft.PowerShell_profile.ps1
More file actions
47 lines (38 loc) · 2.06 KB
/
Microsoft.PowerShell_profile.ps1
File metadata and controls
47 lines (38 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Custom prompt function for PowerShell 7 and PowerShell 5
# To link PS5 profile to PS7's file, run this as admin in PS5:
# mkdir (Split-Path $PROFILE -Parent)
# ni -Type HardLink -Path $PROFILE -Target (pwsh -c `$PROFILE)
function prompt {
# Prompt color based on admin permissions
$isAdmin = (New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
$promptForegroundColor = if($isAdmin) {'DarkYellow'} else {'DarkCyan'}
# check history to see if previous prompt was cancelled
$newHistoryCount = @(Get-History).Count
$previousPromptCancelled = $global:promptHistoryCount -eq $newHistoryCount
$global:promptHistoryCount = $newHistoryCount
if(-not $previousPromptCancelled){
# write blank line and currect directory on a separate line
Write-Host
Write-Host $pwd -ForegroundColor DarkGray
}
# hex codes for '›' and '»' to make it work with PowerShell 5 default encoding
$promptIndicator = if($NestedPromptLevel -lt 1) {[string][char]0x203A} else {[string][char]0x00BB}
$promptIndicator = "$promptIndicator "
# write the main prompt
$promptLength = 0;
if($PSDebugContext) {
# debug mode indicator
$promptText = "[DBG] "
Write-Host $promptText -NoNewLine -ForegroundColor Cyan
$promptLength += $promptText.Length;
}
# PS = PowerShell
$promptText = "PS" #+ $($PSVersionTable.PSVersion.Major) # with version number?
Write-Host $promptText -ForegroundColor $promptForegroundColor -NoNewLine
$promptLength += $promptText.Length;
# set continuation prompt to be on same position as main prompt. U+00B7 is '·' middle dot
$continuationPrompt = [string][char]0x00B7 * $promptLength + "$promptIndicator"
# to make red prompt on syntax error work again.
Set-PSReadLineOption -PromptText "$promptIndicator" -ExtraPromptLineCount 2 -ContinuationPrompt $continuationPrompt -Colors @{ContinuationPrompt = 'Gray'}
$promptIndicator
}