-
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathMicrosoft.PowerShell_profile.ps1
More file actions
185 lines (156 loc) · 5.1 KB
/
Copy pathMicrosoft.PowerShell_profile.ps1
File metadata and controls
185 lines (156 loc) · 5.1 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
# warning
if (!(Get-Command Test-Elevated -ea SilentlyContinue))
{
Write-Host "*** Ensure $PSScriptRoot\Modules\Scripts is in your system env PATH" -ForegroundColor Red
Write-Host "*** temporarily setting path" -ForegroundColor DarkGray
$env:PATH += "$PSScriptRoot\Modules\Scripts"
}
$env:PSElevated = Test-Elevated
# --------------------------------------------------------------------------------------
# default prompt prior loading OhMyPosh
function prompt {
$saveCode = $LASTEXITCODE
if ($env:PSElevated -eq $true) {
Write-Host "PS " -NoNewline -ForegroundColor Red
Write-Host $pwd -NoNewline -ForegroundColor Blue
}
else {
Write-Host "PS $pwd" -NoNewline -ForegroundColor Blue
}
$global:LASTEXITCODE = $saveCode
return "> "
}
# --------------------------------------------------------------------------------------
# cmdlets
function Edit-History
{
[CmdletBinding()]
[Alias('edithistory')]
param()
$0 = (Get-PSReadLineOption).HistorySavePath
if (!(Test-Path $0)) {
Write-Host "*** history path not found: $0" -fo Red
return
}
notepad $0
}
function Go-Profile
{
[CmdletBinding()]
[Alias('pushp', 'profile', 'goprofile', 'push-profile')]
param()
$p = [IO.Path]::GetDirectoryName($profile)
Write-Host "... pushing $p" -fo DarkGray
Push-Location $p
}
function Lock-RDP {
# enable default screensaver and locking behavior
[CmdletBinding()]
[Alias("lock")]
param()
Set-RDP-Screensaver
}
function Unlock-RDP {
# disable default screensaver and locking behavior for RDP sessions
[CmdletBinding()]
[Alias("unlock")]
param()
Set-RDP-Screensaver -Disable
}
function New-Console
{
# start a new PS7 console window, rather than a Windows Terminal
Start-Process conhost.exe -ArgumentList "`"$env:ProgramFiles\PowerShell\7\pwsh.exe`""
}
function Set-SubShellPrompt
{
$env:POSH_THEME = "$env:POSH_THEMES_PATH\paradoxical-subshell.omp.json"
}
function Stop-Edge
{
[CmdletBinding()]
[Alias('stopedge')]
param([switch]$WebView)
taskkill /f /im msedge.exe
if ($WebView) { taskkill /f /im msedgewebview2.exe }
}
function Start-OneMore
{
[CmdletBinding()]
[Alias("onemore")]
param(
[Parameter(ValueFromRemainingArguments = $true)]
[string[]]$Args)
$exe = "C:\Github\OneMore\OneMore\bin\Debug\OneMoreCli.exe"
if (!(Test-Path $exe)) { $exe = "C:\Github\stevencohn\OneMore\OneMore\bin\Debug\OneMoreCli.exe" }
if (!(Test-Path $exe)) { Write-Host "OneMoreCli.exe not found!" -ForegroundColor Red; return }
& $exe @Args
}
function Start-Wilma
{
[CmdletBinding()]
[Alias("wilma")]
param()
& 'C:\Tools\WiLMa\WinLayoutManager.exe'
}
# Command aliases...
. $PSScriptRoot\Modules\Scripts\Set-OutDefaultOverride.ps1
Set-Alias ls Get-ChildItemColorized -Force -Option AllScope
New-Alias Clear-History Clear-HistoryEx -ea SilentlyContinue
New-Alias ep Edit-PSProfile -ea SilentlyContinue
New-Alias hx Get-HistoryEx -ea SilentlyContinue
New-Alias pop Pop-Location -ea SilentlyContinue
New-Alias push Push-Location -ea SilentlyContinue
New-Alias rbh Remove-BrowserHijack -ea SilentlyContinue
New-Alias shell Set-SubShellPrompt -ea SilentlyContinue
New-Alias vs Set-VsDevEnv -ea SilentlyContinue
# Docker helpers
New-Alias doc Remove-DockerTrash -ea SilentlyContinue
New-Alias dos Show-Docker -ea SilentlyContinue
New-Alias dow Start-DockerForWindows -ea SilentlyContinue
# curl.exe is installed as a choco package to \system32; ensure no alias
Remove-Item alias:curl -ErrorAction SilentlyContinue
# --------------------------------------------------------------------------------------
# OK, Go!
# run vsdevcmd.bat if $env:vsdev is set; this is done by conemu task definition
if ($env:vsdev -eq '1') {
Set-VsDevEnv
}
# Chocolatey profile (added by Chocolatey installer)
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
}
$0 = 'C:\Github\ClipboardViewer\bin\Debug\ClipboardViewer.exe'
if (Test-Path $0)
{
function Start-ClipboardViewer
{
[CmdletBinding()]
[Alias("cv")]
param ($p1, $p2, $p3, $p4)
& $0 $p1 $p2 $p3 $p4
}
}
# Win-X-I and Win-X-A will open in %userprofile% and %systemrootm%\system32 respectively.
# Instead, force location to somewhere predictable. But only do this when we open a new
# interactive shell, otherwise it will interfere with command-lines like Flat.bat and modifying
# the current working directory when we don't want it to!
$cmd = (Get-CimInstance win32_process -filter ("ProcessID={0}" -f `
(Get-CimInstance win32_process -filter "ProcessID=$PID").ParentProcessID)).CommandLine
if ($cmd -notmatch 'cmd\.exe')
{
if (Test-Path 'C:\Github') { Set-Location 'C:\Github'; }
elseif (Test-Path 'C:\Code') { Set-Location 'C:\Code'; }
elseif (Test-Path 'C:\River') { Set-Location 'C:\River'; }
else { Set-Location '\'; }
}
if (Test-Path $pwd\PowerShell_profile.ps1)
{
# invoke local folder-specific extensibility script
. $pwd\PowerShell_profile.ps1
}
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\paradoxical.omp.json" | Invoke-Expression
# enable predictive intellisense listview
Set-PSReadLineOption -PredictionSource HistoryAndPlugin
Set-PSReadLineOption -PredictionViewStyle ListView