-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprompt.ps1
65 lines (54 loc) · 1.46 KB
/
prompt.ps1
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# prompt.ps1
# Gives us a more usable prompt.
#
# Author: Nathan Campos <[email protected]>
<#
.SYNOPSIS
Converts an ugly path into a pretty, and hopefully shorter, one. Great for a
prompt.
.PARAMETER Path
Path that we want to prettify.
.OUTPUTS
Hopefully prettified path.
#>
Function Get-PrettyPath() {
Param(
[Parameter(Mandatory = $false)]
[String]$Path = $executionContext.SessionState.Path.CurrentLocation.Path
)
# Check if our path is relative to the user's home directory.
If ($Path.StartsWith($Home)) {
Return $Path.Replace($Home, "~")
}
# Check if our path is an UNC path.
If ($Path.StartsWith("Microsoft.PowerShell.Core\FileSystem::")) {
Return $Path.Replace("Microsoft.PowerShell.Core\FileSystem::", "")
}
# Well, looks like we can't make this one pretty.
Return $Path
}
<#
.SYNOPSIS
The prompt string that we are so familiar with.
.OUTPUTS
A pretty prompt string.
#>
Function prompt() {
$Status = $?
$Path = Get-PrettyPath
$PS1 = ""
# Color codes.
$ESC = [char]27
$Reset = "$ESC[0m"
$Red = "$ESC[31m"
$Yellow = "$ESC[33m"
$Cyan = "$ESC[36m"
# Build up the prompt
$PS1 += If ($Status) { $Cyan } Else { $Red }
$PS1 += "PS${Reset} "
$PS1 += "${Yellow}${Path}"
$PS1 += If ($Path.StartsWith("\\")) { $Red } Else { $Reset }
$PS1 += Write-VcsStatus
$PS1 += "$('>' * ($nestedPromptLevel + 1))${Reset} "
Return $PS1;
}