-
Notifications
You must be signed in to change notification settings - Fork 0
/
powershell.ps1
34 lines (31 loc) · 883 Bytes
/
powershell.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
function Write-BranchName () {
# https://stackoverflow.com/questions/1287718/how-can-i-display-my-current-git-branch-name-in-my-powershell-prompt
$ESC = $([char]27)
try {
$branch = git rev-parse --abbrev-ref HEAD
if ($branch -eq "HEAD") {
$branch = git rev-parse --short HEAD
Write-Host " $ESC[36m($branch)"
}
else {
Write-Host " $ESC[36m($branch)"
}
}
catch {
Write-Host " $ESC[36m(no branches yet)"
}
}
function prompt {
$ESC = $([char]27)
$currentPath = Get-Location
$userPrompt = "$('>' * ($nestedPromptLevel + 1)) "
Write-Host "$ESC[32m$env:USERNAME@$env:COMPUTERNAME" -NoNewLine
Write-Host " $ESC[33m$currentPath" -NoNewLine
if (Test-Path .git) {
Write-BranchName
}
else {
Write-Host
}
return $userPrompt
}