-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMicrosoft.PowerShell_profile.ps1
More file actions
127 lines (116 loc) · 4.18 KB
/
Microsoft.PowerShell_profile.ps1
File metadata and controls
127 lines (116 loc) · 4.18 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
#[Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding #= [System.Text.Utf8Encoding]::new()
#Requires -Version 7.2
[system.Collections.generic.list[scriptblock]] $prompt = @(
{ [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'false flagging')]
$global:promptColor = switch ($global:?) {
$true { "`e[38;5;76m" }
$false { "`e[38;5;196m" }
}
return $null
}
{ "`e[0m" }
{ if ($pwd.Provider.Name -eq 'FileSystem') {
"`e]9;9;`"$($pwd.ProviderPath)`"`e\"
} }
{ "PS " }
{
$path = if ($pwd.Provider.Name -eq "FileSystem") {
try {
$PSStyle.FormatHyperlink($pwd.ProviderPath, "file://localhost/$($pwd.ProviderPath)")
}
catch {
$pwd.ProviderPath
}
}
else {
$pwd.Path
}
$PSStyle.FileInfo.Directory + $PSStyle.Bold + $path + $PSStyle.Reset + ' '
}
{
if (-not (test-path .\.git)) { return; }
try {
$branch = git rev-parse --abbrev-ref HEAD
if ($branch.Length -eq 0) { return $null }
if ($branch -eq "HEAD") {
# we're probably in detached HEAD state, so print the SHA
$branch = git rev-parse --short HEAD
if ($null -eq $branch) { throw }
"$($PSStyle.Foreground.Red)($branch)$($PSStyle.Reset)"
}
else {
# we're on an actual branch, so print it
"$($PSStyle.Foreground.BrightBlue)($branch)$($PSStyle.Reset)"
}
}
catch {
# we'll end up here if we're in a newly initiated git repo
"$($PSStyle.Foreground.Yellow)(no branches yet)$($PSStyle.Reset)"
}
}
{ "`n" }
{ "$global:promptColor$("❯"*($NestedPromptLevel +1))`e[0m " }
)
function prompt {
-join $prompt.invoke()
}
function Restart-Logi {
(Get-Process Logi* )?.kill()
start-process "C:\Program Files\Logitech\LogiOptions\LogiOptions.exe" -ArgumentList '/noui' -verb runas
}
#region helpers
function Clear-Host { [console]::write("`e[0m`e[2J`e[3J`e[0;0H") }
function new-linkeditem([string[]]$files) {
foreach ($file in $files) {
$expanded = Convert-Path $file
if (test-path $expanded -PathType Leaf) {
new-item -path ".\$(Split-Path $expanded -Leaf)" -ItemType HardLink -Value $expanded
}
else {
new-item -path ".\$(Split-Path $expanded -Leaf)" -ItemType SymbolicLink -Value $expanded
}
}
}
#endregion
#region psreadline options
$Local:PSReadLineOptions = @{
ContinuationPrompt = "❯❯";
HistorySearchCursorMovesToEnd = $true;
WordDelimiters = " ;:,.[]{}()/\|^&*-=+'`"–—―_";
}
if ((get-module psreadline).Version -gt 2.2) {
$PSReadLineOptions.PredictionSource = "HistoryAndPlugin"
if ($Env:TERM_PROGRAM -ne "vscode") { $PSReadLineOptions.PredictionViewStyle = "ListView" }
else { $PSReadLineOptions.PredictionViewStyle = "inline" }
}
else { $PSReadLineOptions.PredictionSource = "History" }
$local:historypath = "$($env:OneDriveConsumer ?? "~\OneDrive\")\settings\powershell\ConsoleHost_history.txt"
if (test-path $local:historypath) {
$Local:PSReadLineOptions.HistorySavePath = $local:historypath
}
Set-PSReadLineOption @PSReadLineOptions
Set-PSReadLineKeyHandler -Chord Ctrl+u -ScriptBlock {
[Microsoft.PowerShell.PSConsoleReadLine]::RevertLine()
[Microsoft.PowerShell.PSConsoleReadLine]::Insert('winget upgrade --all')
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
}
. "$(Split-Path $profile -Parent)\PSReadLineProfile.ps1"
#endregion
#endregion style
$PSStyle.Formatting.TableHeader = $PSStyle.Bold + $PSStyle.Foreground.Green
$PSStyle.FileInfo.Directory = $PSStyle.Foreground.Blue
$PSStyle.FileInfo.Extension.Item('.ps1') = $PSStyle.Foreground.BrightYellow
$PSStyle.FileInfo.Extension.Item('.psd1') = $PSStyle.Foreground.BrightYellow
$PSStyle.FileInfo.Extension.Item('.psm1') = $PSStyle.Foreground.BrightYellow
$PSStyle.FileInfo.Extension.Item('.ps1xml') = $PSStyle.Foreground.BrightYellow
$PSStyle.FileInfo.Extension.add('.pdf', $PSStyle.Foreground.BrightWhite + $PSStyle.Background.red)
$PSStyle.Formatting.FormatAccent = $PSStyle.Bold + $PSStyle.Foreground.Green
$PSStyle.Progress.MaxWidth = [console]::BufferWidth
$PSStyle.Progress.UseOSCIndicator = $true
#endregion
if (test-path "~\Source\Repos\powershell-utils") {
if ($env:path[$env:path.Length - 1] -ne ';') {
$env:path += ';'
}
$env:path += "$env:USERPROFILE\Source\Repos\powershell-utils"
}