-
Notifications
You must be signed in to change notification settings - Fork 15
/
user-profile.ps1
119 lines (96 loc) · 3.26 KB
/
user-profile.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
# Use this file to run your own startup commands
#######################################
# Prompt Customization
#######################################
<#
.SYNTAX
<PrePrompt><CMDER DEFAULT>
λ <PostPrompt> <repl input>
.EXAMPLE
<PrePrompt>N:\Documents\src\cmder [master]
λ <PostPrompt> |
#>
[ScriptBlock]$PrePrompt = {
}
function Import-GitModule($Loaded){
if($Loaded) { return }
$GitModule = Get-Module -Name Posh-Git -ListAvailable
if($GitModule | Select-Object version | Where-Object version -le ([version]"0.6.1.20160330")){
Import-Module Posh-Git > $null
}
if(-not ($GitModule) ) {
Write-Warning "Missing git support, install posh-git with 'Install-Module posh-git' and restart cmder."
}
# Make sure we only run once by alawys returning true
return $true
}
$isGitLoaded = $false
#Anonymice Powerline
$arrowSymbol = [char]0xE0B0;
$branchSymbol = [char]0xE0A0;
$defaultForeColor = "White"
$defaultBackColor = "Black"
$pathForeColor = "White"
$pathBackColor = "DarkBlue"
$gitCleanForeColor = "White"
$gitCleanBackColor = "Green"
$gitDirtyForeColor = "Black"
$gitDirtyBackColor = "Yellow"
function Write-GitPrompt() {
$status = Get-GitStatus
if ($status) {
# assume git folder is clean
$gitBackColor = $gitCleanBackColor
$gitForeColor = $gitCleanForeColor
if ($status.HasWorking -Or $status.HasIndex) {
# but if it's dirty, change the back color
$gitBackColor = $gitDirtyBackColor
$gitForeColor = $gitDirtyForeColor
}
# Close path prompt
Write-Host $arrowSymbol -NoNewLine -BackgroundColor $gitBackColor -ForegroundColor $pathBackColor
# Write branch symbol and name
Write-Host " " $branchSymbol " " $status.Branch " " -NoNewLine -BackgroundColor $gitBackColor -ForegroundColor $gitForeColor
<# Git status info
HasWorking : False
Branch : master
AheadBy : 0
Working : {}
Upstream : origin/master
StashCount : 0
Index : {}
HasIndex : False
BehindBy : 0
HasUntracked : False
GitDir : D:\amr\SourceCode\DevDiary\.git
#>
# close git prompt
Write-Host $arrowSymbol -NoNewLine -BackgroundColor $defaultBackColor -ForegroundColor $gitBackColor
}
}
function getGitStatus($Path) {
if (Test-Path -Path (Join-Path $Path '.git') ) {
$isGitLoaded = Import-GitModule $isGitLoaded
Write-GitPrompt
return
}
$SplitPath = split-path $path
if ($SplitPath) {
getGitStatus($SplitPath)
}
else{
Write-Host $arrowSymbol -NoNewLine -ForegroundColor $pathBackColor
}
}
function tildaPath($Path) {
return $Path.replace($env:USERPROFILE, "~")
}
# Replace the cmder prompt entirely with this.
[ScriptBlock]$CmderPrompt = {
$tp = tildaPath($pwd.ProviderPath)
Microsoft.PowerShell.Utility\Write-Host "`n" $tp " " -NoNewLine -BackgroundColor $pathBackColor -ForegroundColor $pathForeColor
getGitStatus($pwd.ProviderPath)
}
[ScriptBlock]$PostPrompt = {
}
## <Continue to add your own>