-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprompt.ps1
168 lines (136 loc) · 6.69 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# fork of prompt.ps1 for powerline prompt: https://gist.github.com/kadet1090/86023bfad2bdd84d8b1a
$script:bg = [Console]::BackgroundColor;
$script:admin = $false;
$script:first = $true;
$script:last = 0;
$script:max_path_length = 40;
If (([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] “Administrator”))
{
$script:admin = $true;
}
function Write-PromptFancyEnd {
Write-Host -NoNewline -ForegroundColor $script:bg
$script:bg = [System.ConsoleColor]::Black
}
function Write-PromptSegment {
param(
[Parameter(
Position=0,
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true
)][string]$Text,
[Parameter(Position=1)][System.ConsoleColor] $Background = [Console]::BackgroundColor,
[Parameter(Position=2)][System.ConsoleColor] $Foreground = [System.ConsoleColor]::White
)
if(!$script:first) {
Write-Host -NoNewline -BackgroundColor $Background -ForegroundColor $script:bg
} else {
$script:first = $false
}
Write-Host $text -NoNewline -BackgroundColor $Background -ForegroundColor $Foreground
$script:bg = $background;
}
function Get-FancyDir {
$max = $script:max_path_length;
$dir = $(Get-Location).ToString();
if (($max -gt 0) -and ($dir.length -gt $max)) {
$dir = $dir -replace "^([^\\]+)\\([^\\]+)\\.+\\(.*)",'$1\$2\…\$3'
}
return $dir.Replace($env:USERPROFILE, '~').Replace('\', ' ');
}
function Get-GitBranch {
$HEAD = Get-Content $(Join-Path $(Get-GitDirectory) HEAD)
if($HEAD -like 'ref: refs/heads/*') {
return $HEAD -replace 'ref: refs/heads/(.*?)', "$1";
} else {
return $HEAD.Substring(0, 8);
}
}
function Get-GitStatusText {
Write-PromptSegment " " DarkBlue White
$global:GitPromptSettings.BeforeText = ""
$global:GitPromptSettings.BeforeBackgroundColor = [ConsoleColor]::DarkBlue
$global:GitPromptSettings.DelimForegroundColor = [ConsoleColor]::White
$global:GitPromptSettings.DelimBackgroundColor = [ConsoleColor]::DarkBlue
$global:GitPromptSettings.AfterText = ''
#$global:GitPromptSettings.FileAddedText = '+'
#$global:GitPromptSettings.FileModifiedText = '~'
#$global:GitPromptSettings.FileRemovedText = '-'
#$global:GitPromptSettings.FileConflictedText = '!'
$global:GitPromptSettings.LocalWorkingStatusSymbol = '!'
$global:GitPromptSettings.LocalWorkingStatusForegroundColor = [ConsoleColor]::DarkRed
$global:GitPromptSettings.LocalWorkingStatusForegroundBrightColor = [ConsoleColor]::Red
$global:GitPromptSettings.LocalWorkingStatusBackgroundColor = [ConsoleColor]::DarkBlue
$global:GitPromptSettings.LocalStagedStatusSymbol = '~'
$global:GitPromptSettings.LocalStagedStatusForegroundColor = [ConsoleColor]::Cyan
$global:GitPromptSettings.LocalStagedStatusBackgroundColor = [ConsoleColor]::DarkBlue
$global:GitPromptSettings.BranchUntrackedSymbol = $null
$global:GitPromptSettings.BranchForegroundColor = [ConsoleColor]::White
$global:GitPromptSettings.BranchBackgroundColor = [ConsoleColor]::DarkBlue
$global:GitPromptSettings.BranchIdenticalStatusToSymbol = [char]0x2261 # Three horizontal lines
$global:GitPromptSettings.BranchIdenticalStatusToForegroundColor = [ConsoleColor]::Gray
$global:GitPromptSettings.BranchIdenticalStatusToBackgroundColor = [ConsoleColor]::DarkBlue
$global:GitPromptSettings.BranchAheadStatusSymbol = [char]0x2191 # Up arrow
$global:GitPromptSettings.BranchAheadStatusForegroundColor = [ConsoleColor]::Green
$global:GitPromptSettings.BranchAheadStatusBackgroundColor = [ConsoleColor]::DarkBlue
$global:GitPromptSettings.BranchBehindStatusSymbol = [char]0x2193 # Down arrow
$global:GitPromptSettings.BranchBehindStatusForegroundColor = [ConsoleColor]::Red
$global:GitPromptSettings.BranchBehindStatusBackgroundColor = [ConsoleColor]::DarkBlue
$global:GitPromptSettings.BranchBehindAndAheadStatusSymbol = [char]0x2195 # Up & Down arrow
$global:GitPromptSettings.BranchBehindAndAheadStatusForegroundColor = [ConsoleColor]::Yellow
$global:GitPromptSettings.BranchBehindAndAheadStatusBackgroundColor = [ConsoleColor]::DarkBlue
$global:GitPromptSettings.BeforeIndexText = ""
$global:GitPromptSettings.BeforeIndexForegroundColor = [ConsoleColor]::DarkGreen
$global:GitPromptSettings.BeforeIndexForegroundBrightColor = [ConsoleColor]::DarkGreen
$global:GitPromptSettings.BeforeIndexBackgroundColor = [ConsoleColor]::DarkBlue
$global:GitPromptSettings.IndexForegroundColor = [ConsoleColor]::Black
$global:GitPromptSettings.IndexForegroundBrightColor = [ConsoleColor]::DarkGray
$global:GitPromptSettings.IndexBackgroundColor = [ConsoleColor]::DarkBlue
$global:GitPromptSettings.WorkingForegroundColor = [ConsoleColor]::White
$global:GitPromptSettings.WorkingForegroundBrightColor = [ConsoleColor]::Gray
$global:GitPromptSettings.WorkingBackgroundColor = [ConsoleColor]::DarkBlue
$(Write-VcsStatus)
}
function Write-PromptStatus {
if($script:last) {
Write-PromptSegment ' ✔ ' DarkGreen Black
} else {
Write-PromptSegment " ✖ $lastexitcode " DarkRed White
}
}
function Write-PromptUser {
if($script:admin) {
Write-PromptSegment ' ₪ ADMIN → ' Magenta White;
} else {
Write-PromptSegment " $env:USERNAME " DarkGray Yellow;
}
}
function Write-PromptVirtualEnv {
if($env:VIRTUAL_ENV) {
Write-PromptSegment " $(split-path $env:VIRTUAL_ENV -leaf) " Cyan Black
}
}
function Write-PromptDir {
Write-PromptSegment " $(Get-FancyDir) " Yellow Black
}
# Depends on posh-git
function Write-PromptGit {
if (Get-Command -Name Get-GitDirectory -errorAction SilentlyContinue) {
if (Get-GitDirectory) {
Write-PromptSegment " $(Get-GitStatusText)" DarkBlue White
}
}
}
function prompt {
$script:last = $?;
$script:first = $true;
Write-PromptStatus
Write-PromptUser
Write-PromptVirtualEnv
Write-PromptDir
Write-PromptGit
Write-PromptFancyEnd
return ' '
}