-
Notifications
You must be signed in to change notification settings - Fork 0
/
Microsoft.PowerShell_profile.ps1
47 lines (43 loc) · 1.34 KB
/
Microsoft.PowerShell_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
Set-PSReadlineKeyHandler -Key ctrl+d -Function ViExit
function which { (Get-Command $args).Definition }
Set-Alias vim nvim
Set-Alias lg lazygit
function Get-BranchName {
try {
$branch = git rev-parse --abbrev-ref HEAD
$str = ""
if ($branch -eq "HEAD") {
$str += " ("
$str += git rev-parse --short HEAD
$str += ")"
}
elseif ($branch) {
$str += " ($branch)"
}
$dirty = git status --porcelain
if($dirty) {
$str += "*"
}
return $str;
} catch { return "" }
}
function Get-Role {
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = [Security.Principal.WindowsPrincipal] $identity
$adminRole = [Security.Principal.WindowsBuiltInRole]::Administrator
$(if (Test-Path variable:/PSDebugContext) { '[DBG]: ' }
elseif($principal.IsInRole($adminRole)) { '[ADMIN]: ' }
else { '' }
)
}
function prompt {
$path = "$($executionContext.SessionState.Path.CurrentLocation)"
$branch = $(Get-BranchName)
Write-Host -NoNewline $(Get-Role)
Write-Host -NoNewline "PS "
Write-Host -NoNewline "$env:UserName@$env:ComputerName" -ForegroundColor "green"
Write-Host -NoNewline ":" -ForegroundColor "white"
Write-Host -NoNewline $path -ForegroundColor "blue"
Write-Host -NoNewline $branch -ForegroundColor "DarkYellow"
return "$('>' * ($nestedPromptLevel + 1)) "
}