-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Microsoft.PowerShell_profile.ps1
60 lines (47 loc) · 1.36 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
48
49
50
51
52
53
54
55
56
57
58
59
60
function Get-GitBranch
{
$git = Get-Command git
if ($git -eq $null) {
return $null
}
$branch = git branch -a 2> $null | Where-Object {$_ -match "^\*"}
if ($branch -eq $null) {
return $null
}
$branch = $branch.Substring(2)
if ($branch -match "^\(.*\)$") {
$branch = (git name-rev HEAD 2> $null).Substring(5)
}
$workdir = ([io.fileinfo](git workdir 2> $null)).basename
"$($workdir):$($branch)"
}
function prompt
{
$exit = $LastExitCode
if ($exit -eq $null) {
$exit = 0
}
$git = Get-GitBranch
if ($git -ne $null) {
$git = "[$git] "
}
# Reset $LastExitCode so we don't get confusing things happening because of stuff we've run
cmd /c "exit $($exit)"
# Right prompt
$rprompt = "[$($exit)]"
Write-Host (" " * ($host.ui.rawui.windowsize.width - $rprompt.length - 1) + "$($rprompt)`r") -NoNewline -ForegroundColor DarkGray
# Left prompt
Write-Host ("$($executionContext.SessionState.Path.CurrentLocation) ") -NoNewline -ForegroundColor DarkGreen
Write-Host ($git) -NoNewline -ForegroundColor DarkRed
"$('$' * ($nestedPromptLevel + 1)) "
}
function which($cmd)
{
Get-Command $cmd | Format-List *
}
$env:EDITOR = "notepad++.exe"
Set-Alias ssh plink
Set-Alias scp pscp
# This is the same as ls, include for linux compat
Set-Alias ll Get-ChildItem
function la { Get-ChildItem -Force }