-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMicrosoft.PowerShell_profile.ps1
More file actions
362 lines (312 loc) · 11.7 KB
/
Microsoft.PowerShell_profile.ps1
File metadata and controls
362 lines (312 loc) · 11.7 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# Icons
$script:CursorIcon = [char]0x276F # provided by ChatGPT
$script:BranchIcon = [char]0xe0a0 # nf-pl-branch
$script:DotnetIcon = [char]0xe77f # nf-dev-dotnet
# $script:DotnetIcon = [char]0xDB82 + [char]0xDEAE # nf-md-dot_net
$script:RustIcon = [char]0xe7a8 # nf-dev-rust
$script:CIcon = [char]0xe61e # nf-custom-c
$script:PythonIcon = [char]0xe73c # nf-dev-python
$script:MarkdownIcon = [char]0xe73e # nf-dev-markdown
$script:GitFolderIcon = [char]0xe5fb # nf-custom-folder_git
$script:TimerIcon = [char]0xdb81 + [char]0xdd1b # nf-md-timer_outline
# Powerline
$script:PowerlineRightRound = [char]0xE0B4
$script:PowerlineLeftRound = [char]0xE0B6
$script:PowerlineRightTriangle = [char]0xE0B0
$script:PowerlineLeftTriangle = [char]0xE0B2
$script:PowerlineSmallPixelRight = [char]0xE0C4
$script:PowerlineSmallPixelLeft = [char]0xE0C5
# Colors - Rose Pine
## Clear
$script:Clear = "`e[0m"
## Dawn
$script:DawnBaseBackground = "`e[48;2;250;244;237m"
$script:DawnBaseForeground = "`e[38;2;250;244;237m"
$script:DawnTextBackground = "`e[48;2;87;82;121m"
$script:DawnTextForeground = "`e[38;2;87;82;121m"
$script:DawnLoveBackground = "`e[48;2;180;99;122m"
$script:DawnLoveForeground = "`e[38;2;180;99;122m"
$script:DawnGoldBackground = "`e[48;2;234;157;52m"
$script:DawnGoldForeground = "`e[38;2;234;157;52m"
$script:DawnRoseBackground = "`e[48;2;215;130;126m"
$script:DawnRoseForeground = "`e[38;2;215;130;126m"
$script:DawnPineBackground = "`e[48;2;40;105;131m"
$script:DawnPineForeground = "`e[38;2;40;105;131m"
$script:DawnFoamBackground = "`e[48;2;86;148;159m"
$script:DawnFoamForeground = "`e[38;2;86;148;159m"
$script:DawnIrisBackground = "`e[48;2;144;122;169m"
$script:DawnIrisForeground = "`e[38;2;144;122;169m"
## Moon
$script:MoonBaseBackground = "`e[48;2;35;33;54m"
$script:MoonBaseForeground = "`e[38;2;35;33;54m"
$script:MoonTextForeground = "`e[48;2;224;222;244m"
$script:MoonTextForeground = "`e[38;2;224;222;244m"
$script:MoonLoveBackground = "`e[48;2;235;111;146m"
$script:MoonLoveForeground = "`e[38;2;235;111;146m"
$script:MoonGoldBackground = "`e[48;2;246;193;119m"
$script:MoonGoldForeground = "`e[38;2;246;193;119m"
$script:MoonRoseBackground = "`e[48;2;234;154;151m"
$script:MoonRoseForeground = "`e[38;2;234;154;151m"
$script:MoonPineBackground = "`e[48;2;62;143;176m"
$script:MoonPineForeground = "`e[38;2;62;143;176m"
$script:MoonFoamBackground = "`e[48;2;156;207;216m"
$script:MoonFoamForeground = "`e[38;2;156;207;216m"
$script:MoonIrisBackground = "`e[48;2;196;167;231m"
$script:MoonIrisForeground = "`e[38;2;196;167;231m"
#Buffers
$script:builder = [System.Text.StringBuilder]::new()
# Override default prompt
function prompt {
$start = [System.TimeProvider]::System.GetTimestamp()
$git = Get-GitStats
# Acquiring the language version can be slow.
$programmingLanguage = Get-Language -MaxTopLevel $git.TopLevel -OmitLanguageVersion:$false
if ($git.IsGit -eq $false -and $null -eq $programmingLanguage) {
Add-PromptText (Get-PathSegment)
Add-PromptSeparator
Add-PromptElapsed -Start $start
Get-PromptText
}
else {
$relativePath = $null
if ($null -ne $programmingLanguage) {
Add-PromptText $programmingLanguage
}
if ($git.IsGit) {
Add-PromptSeparator
if ($null -ne $git.Branch) {
Add-PromptText "$($git.Branch) "
}
Add-PromptText "$($git.Commit) $($script:MoonPineForeground)+$($git.AddedFiles) $($script:MoonLoveForeground)-$($git.DeletedFiles) $($script:MoonRoseForeground)~$($git.ModifiedFiles)"
$relativePath = $PWD.Path.Substring((Split-Path -Parent -Path $git.TopLevel).Length + 1)
}
else {
$relativePath = Get-PathSegment
}
Add-PromptSeparator
Add-PromptElapsed -Start $start
Write-Host (Get-PromptText)
Add-PromptText $relativePath
Get-PromptText
}
}
function Format-Measure {
param ($MeasureResult)
"$($MeasureResult.Milliseconds) ms $($MeasureResult.Microseconds) us $($MeasureResult.Nanoseconds) ns"
}
function Clear-PromptText {
$script:builder.Clear() | Out-Null
}
function Get-PromptText {
Add-PromptText $script:MoonGoldForeground
Add-PromptText " $($script:CursorIcon) "
Add-PromptText $script:Clear
$final = $script:builder.ToString()
Clear-PromptText
return $final
}
function Add-PromptText {
param ([string]$Text)
$script:builder.Append($Text) | Out-Null
}
function Add-PromptSeparator {
Add-PromptText $script:MoonGoldForeground
Add-PromptText " $($script:CursorIcon) "
Add-PromptText $script:Clear
}
function Add-PromptElapsed {
param ([Int64]$Start)
$elapsed = [System.TimeProvider]::System.GetElapsedTime($Start)
Add-PromptText "$([System.String]::Format('{0:F0}', $elapsed.TotalMilliseconds)) ms"
}
function Get-PathSegment {
$currentDirectory = $PWD.Path
$currentDirectoryPathing = $currentDirectory -split '\\'
if ($currentDirectoryPathing.Length -gt 2) {
return "$($currentDirectoryPathing[0])\...\$($currentDirectoryPathing[-1])"
}
else {
return $currentDirectory
}
}
function Get-Language {
[CmdletBinding()]
param (
[Parameter(Mandatory = $false, Position = 0)]
[string]
$SearchPath = '.',
[Parameter(Mandatory = $false, Position = 1)]
[string]
[AllowNull()]
[AllowEmptyString()]
$MaxTopLevel = '',
[switch]
$OmitLanguageVersion
)
$safeSearchPath = (Resolve-Path -Path $SearchPath).Path
$files = @(Get-ChildItem -Path $safeSearchPath -File)
if ($files.Count -gt 0) {
foreach ($file in $files) {
if ($file.Extension -eq '.cs' -or $file.Extension -eq ".csproj" -or $file.Extension -eq ".sln" -or $file.Extension -eq ".slnx") {
# every .NET icon has a spacing issue. We'll add space as our best ability.
if ($OmitLanguageVersion) {
return "$($script:DotnetIcon) "
}
else {
return "$($script:DotnetIcon) $(Get-CurrentDotnetVersion)"
}
}
}
foreach ($file in $files) {
if ($file.Extension -eq '.cpp' -or $file.Extension -eq ".hpp" -or $file.Extension -eq ".h" -or $file.Extension -eq ".c" -or $file.Extension -eq ".vcxproj") {
return "$($script:CIcon)"
}
}
foreach ($file in $files) {
if ($file.Extension -eq ".rs" -or $file.Name -ieq "Cargo.toml") {
return "$($script:RustIcon)"
}
}
foreach ($file in $files) {
if ($file.Extension -eq ".py") {
return "$($script:PythonIcon)"
}
}
foreach ($file in $files) {
if ($file.Extension -eq ".md") {
return "$($script:MarkdownIcon)"
}
}
if ([string]::IsNullOrEmpty($MaxTopLevel) -eq $false) {
if ($safeSearchPath.Length -gt $MaxTopLevel.Length) {
$upperLanguage = Get-Language -SearchPath (Split-Path -Parent $safeSearchPath) -MaxTopLevel $MaxTopLevel
if ($null -ne $upperLanguage) {
return $upperLanguage
}
}
}
}
return $null
}
function Get-GitTopLevel {
$topLevel = (git --no-optional-locks rev-parse --show-toplevel 2>$null)
if ($null -ne $topLevel) {
return $topLevel
}
return $null
}
function Get-GitStatus {
$porcelain = (git --no-optional-locks status --porcelain=v2 --branch --untracked-files=no 2>$null)
if ($null -ne $porcelain) {
return $porcelain
}
return $null
}
function Get-GitStats {
$gitStatus = Get-GitStatus
if ($null -ne $gitStatus) {
$branch = $null
$commit = $null
$upstream = $null
$untrackedFilesCount = 0
$addedFilesCount = 0
$modifiedFilesCount = 0
$deletedFilesCount = 0
$renamedFilesCount = 0
$copiedFilesCount = 0
$typeChangedFilesCount = 0
$unmergedFilesCount = 0
$ignoredFilesCount = 0
foreach ($line in $gitStatus) {
# Headers
if ($line[0] -eq "#") {
# branch.oid
if ($line[9] -eq "o") {
# if ($line -match 'initial') {
if ($line[13] -ne "(") {
$commit = $line.Substring(13, 8)
}
}
# branch.head
elseif ($line[9] -eq "h") {
$branch = $line.Substring(14)
}
# branch.upstream
elseif ($line[9] -eq "u") {
$upstream = $line.Substring(18)
}
}
elseif ($line[0] -eq "?") {
$untrackedFilesCount++;
}
elseif ($line[0] -eq "!") {
$ignoredFilesCount++;
}
else {
# XY has two characters, but we'll just use the first as the main change.
$xy = $line[2]
# Align with expected frequency of change type
if ($xy -eq "M") {
$modifiedFilesCount++;
}
elseif ($xy -eq "A") {
$addedFilesCount++;
}
elseif ($xy -eq "D") {
$deletedFilesCount++;
}
elseif ($xy -eq "R") {
$renamedFilesCount++;
}
elseif ($xy -eq "C") {
$copiedFilesCount++;
}
elseif ($xy -eq "T") {
$typeChangedFilesCount++;
}
elseif ($xy -eq "U") {
$unmergedFilesCount++;
}
}
}
$topLevel = Get-GitTopLevel
return [PSCustomObject]@{
IsGit = $true
TopLevel = $topLevel
Branch = $branch
Commit = $commit
Upstream = $upstream
UntrackedFiles = $untrackedFilesCount
AddedFiles = $addedFilesCount
ModifiedFiles = $modifiedFilesCount
DeletedFiles = $deletedFilesCount
RenamedFiles = $renamedFilesCount
CopiedFiles = $copiedFilesCount
TypeChangedFiles = $typeChangedFilesCount
UnmergedFiles = $unmergedFilesCount
IgnoredFiles = $ignoredFilesCount
}
}
return [PSCustomObject]@{
IsGit = $false
}
}
function Get-CurrentDotnetVersion {
$dotnetVersion = (dotnet --version 2>$null)
if ($LASTEXITCODE -eq 0 -and $null -ne $dotnetVersion) {
return $dotnetVersion
}
return $null
}
# Import the Chocolatey Profile.
# See https://ch0.co/tab-completion for details.
$ChocolateyProfile = [System.IO.Path]::Combine($env:ChocolateyInstall, 'helpers', 'chocolateyProfile.psm1')
if ([System.IO.File]::Exists($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
}
# Disable highlighting of directories.
$PSStyle.FileInfo.Directory = ""
# Enable history picker by default.
Set-PSReadLineOption -HistoryNoDuplicates -PredictionViewStyle ListView
# Set to dev drive repos
Set-Location -Path 'D:\repos'