forked from donovanlange/WindowsPowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Profile.ps1
180 lines (148 loc) · 4.74 KB
/
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
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
169
170
171
172
173
174
175
176
177
178
179
180
# ---------------------------------------------------------------------------
# Settings
# ---------------------------------------------------------------------------
$MaximumHistoryCount = 512
$FormatEnumerationLimit = 100
# ---------------------------------------------------------------------------
# Modules
# ---------------------------------------------------------------------------
# PSReadline provides Bash like keyboard cursor handling
if ($host.Name -eq 'ConsoleHost')
{
Import-Module PSReadline
Set-PSReadLineOption -MaximumHistoryCount 4000
Set-PSReadlineOption -ShowToolTips:$true
# With these bindings, up arrow/down arrow will work like
# PowerShell/cmd if the current command line is blank. If you've
# entered some text though, it will search the history for commands
# that start with the currently entered text.
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward
Set-PSReadlineKeyHandler -Key "Tab" -Function "MenuComplete"
Set-PSReadlineKeyHandler -Chord 'Shift+Tab' -Function "Complete"
}
# fzf is a fuzzy file finder, and will provide fuzzy location searching
# when using Ctrl+T, and will provide better reverse command searching via
# Ctrl-R.
Import-Module PSFzf -ArgumentList 'Ctrl+T','Ctrl+R'
# Git support
Import-Module Git
Initialize-Git
Import-Module Posh-Git
# Colorize directory output
Import-Module PSColor
# Utils
Import-Module StreamUtils
Import-Module StringUtils
Import-Module Profile
# ---------------------------------------------------------------------------
# Custom Aliases
# ---------------------------------------------------------------------------
set-alias unset remove-variable
set-alias mo measure-object
set-alias eval invoke-expression
set-alias n 'notepad.exe'
set-alias vi vim.exe
# ---------------------------------------------------------------------------
# Visuals
# ---------------------------------------------------------------------------
#set-variable -Scope Global WindowTitle ''
function ShouldRepoBeExcludedForGitStatus
{
# Personal preference: ignore any directory under %INETROOT%, as these are VERY large Git repos
$local:inetRoot = $null
if (Test-Path env:\INETROOT)
{
$local:inetRoot = $(get-content env:\INETROOT)
}
if ($local:inetRoot)
{
$local:inetRoot = $local:inetRoot.ToLower()
$local:currentDir = (get-location).Path.ToLower()
return $local:currentDir.StartsWith($local:inetRoot)
}
return $false
}
function prompt
{
$local:pathObj = (get-location)
$local:path = $pathObj.Path
$local:drive = $pathObj.Drive.Name
if(!$drive) # if there's no drive, it might be a special path (eg, a UNC path)
{
if($path.contains('::')) # if it's a special path, get the provider's path name
{
$path = $pathObj.ProviderPath
}
if($path -match "^\\\\([^\\]+)\\") # if it's a UNC path, use the server name as the drive
{
$drive = $matches[1]
}
}
$local:title = $path
if($WindowTitle) { $title += " - $WindowTitle" }
$path = [IO.Path]::GetFileName($path)
if(!$path) { $path = '\' }
if($NestedPromptLevel)
{
Write-Host -NoNewline -ForeGroundColor Green "$NestedPromptLevel-";
}
$private:h = @(Get-History);
$private:nextCommand = $private:h[$private:h.Count - 1].Id + 1;
Write-Host -NoNewline -ForeGroundColor Red "${private:nextCommand}|";
Write-Host -NoNewline -ForeGroundColor Blue "${drive}";
Write-Host -NoNewline -ForeGroundColor White ":";
Write-Host -NoNewline -ForeGroundColor White "$path";
# Show GIT Status, if loaded:
if (Get-Command "Write-VcsStatus" -ErrorAction SilentlyContinue)
{
if (!(ShouldRepoBeExcludedForGitStatus))
{
$realLASTEXITCODE = $LASTEXITCODE
Write-VcsStatus
$global:LASTEXITCODE = $realLASTEXITCODE
}
}
$host.ui.rawUi.windowTitle = $title
return ">";
}
# ---------------------------------------------------------------------------
# Helper functions
# ---------------------------------------------------------------------------
# starts a new execution scope
function Start-NewScope
{
param($Prompt = $null) Write-Host "Starting New Scope"
if ($Prompt -ne $null)
{
if ($Prompt -is [ScriptBlock])
{
$null = New-Item function:Prompt -Value $Prompt -force
}
else
{
function Prompt {"$Prompt"}
}
}
$host.EnterNestedPrompt()
}
# 'cause shutdown commands are too long and hard to type...
function Restart
{
shutdown /r /t 1
}
# --------------------------------------------------------------------------
# EXO Helpers
# --------------------------------------------------------------------------
function dev($project)
{
cd "$(get-content Env:INETROOT)\sources\dev\$project"
}
function test($project)
{
cd "$(get-content Env:INETROOT)\sources\test\$project"
}
function bcc
{
build -Cc
}