-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMicrosoft.PowerShell_profile.ps1
278 lines (238 loc) · 7.51 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
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
# boxmein's powershell config
# ps core 7.2.2 || microsoft ps 5.0 something
chcp 65001
#region Environment add-ons
$env:PYTHONIOENCODING = "utf-8"
$env:EDITOR = "code.cmd"
$env:VISUAL = "code.cmd"
$env:ALTERNATIVE_EDITOR = "notepad"
$env:PGCLIENTENCODING = "utf-8"
#endregion
${function:~} = { Set-Location ~ }
#region Aliases
# Dot dot
${function:Set-ParentLocation} = { Set-Location .. };
Set-Alias ".." Set-ParentLocation
${function:...} = { Set-Location ..\.. }
${function:....} = { Set-Location ..\..\.. }
${function:.....} = { Set-Location ..\..\..\.. }
${function:......} = { Set-Location ..\..\..\..\.. }
Set-Alias -Option AllScope -Name cat -Value get-content
Set-Alias -Option AllScope -Name cd -Value set-location
Set-Alias -Option AllScope -Name clear -Value clear-host
Set-Alias -Option AllScope -Name cp -Value copy-item
Set-Alias -Option AllScope -Name h -Value get-history
Set-Alias -Option AllScope -Name history -Value get-history
Set-Alias -Option AllScope -Name kill -Value stop-process
Set-Alias -Option AllScope -Name lp -Value out-printer
Set-Alias -Option AllScope -Name mount -Value new-mshdrive
Set-Alias -Option AllScope -Name mv -Value move-item
Set-Alias -Option AllScope -Name popd -Value pop-location
Set-Alias -Option AllScope -Name ps -Value get-process
Set-Alias -Option AllScope -Name pushd -Value push-location
Set-Alias -Option AllScope -Name pwd -Value get-location
Set-Alias -Option AllScope -Name r -Value invoke-history
Set-Alias -Option AllScope -Name rm -Value remove-item
Set-Alias -Option AllScope -Name rmdir -Value remove-item
Set-Alias -Option AllScope -Name echo -Value write-output
Set-Alias -Option AllScope -Name rd -Value remove-item
Set-Alias -Option AllScope -Name set -Value set-variable
Set-Alias -Option AllScope -Name nslookup -Value Resolve-DnsName
Set-Alias time Measure-Command
${function:sv} = { Set-Location D:\Projects\Calidity\ }
${function:svctl} = { Set-Location D:\Projects\Calidity\controller }
${function:svdev} = { Set-Location D:\Projects\Calidity\dev }
${function:svsf} = { Set-Location D:\Projects\Calidity\dev\frontend }
${function:dl} = { Set-Location ~\Downloads }
#endregion
##region MORE COMPLEX ALIASES
function dig {
Resolve-DnsName -Type $args[0] -Name $args[1]
}
function settings {
code.cmd "$env:USERPROFILE\dotfiles\Microsoft.PowerShell_profile.ps1"
}
function help {
get-help $args[0] | out-host -paging
}
function mkdir {
new-item -type directory -path $args
}
function md {
new-item -type directory -path $args
}
function prompt {
"PS " + $(get-location) + "> "
}
function gs {
git status $args
}
function ga {
git add $args
}
function gc {
git commit $args
}
function gp {
git push $args
}
function which($name) {
Get-Command $name -ErrorAction SilentlyContinue | Select-Object Definition
}
function touch($file) {
"" | Out-File $file -Encoding ASCII
}
function dbc {
$env:PGPASSWORD = "postgres"
psql -U postgres -h localhost -d postgres
}
# Sudo
function sudo() {
if ($args.Length -eq 1) {
start-process $args[0] -verb "runAs"
}
if ($args.Length -gt 1) {
start-process $args[0] -ArgumentList $args[1..$args.Length] -verb "runAs"
}
}
#endregion
#region bla
function Edit-Hosts {
Invoke-Expression "sudo $(if($null -ne $env:EDITOR) { $env:EDITOR } else { 'notepad' }) $env:windir\system32\drivers\etc\hosts"
}
function Edit-Profile {
Invoke-Expression "$(if($null -ne $env:EDITOR) {$env:EDITOR } else { 'notepad' }) $profile"
}
function Restart-Powershell {
$newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";
$newProcess.Arguments = "-nologo";
[System.Diagnostics.Process]::Start($newProcess);
exit
}
# Sound Volume
function Get-SoundVolume {
<#
.SYNOPSIS
Get audio output volume.
.DESCRIPTION
The Get-SoundVolume cmdlet gets the current master volume of the default audio output device. The returned value is an integer between 0 and 100.
.LINK
Set-SoundVolume
.LINK
Set-SoundMute
.LINK
Set-SoundUnmute
.LINK
https://github.com/jayharris/dotfiles-windows/
#>
[math]::Round([Audio]::Volume * 100)
}
function Set-SoundVolume([Parameter(mandatory = $true)][Int32] $Volume) {
<#
.SYNOPSIS
Set audio output volume.
.DESCRIPTION
The Set-SoundVolume cmdlet sets the current master volume of the default audio output device to a value between 0 and 100.
.PARAMETER Volume
An integer between 0 and 100.
.EXAMPLE
Set-SoundVolume 65
Sets the master volume to 65%.
.EXAMPLE
Set-SoundVolume -Volume 100
Sets the master volume to a maximum 100%.
.LINK
Get-SoundVolume
.LINK
Set-SoundMute
.LINK
Set-SoundUnmute
.LINK
https://github.com/jayharris/dotfiles-windows/
#>
[Audio]::Volume = ($Volume / 100)
}
function Set-SoundMute {
<#
.SYNOPSIS
Mote audio output.
.DESCRIPTION
The Set-SoundMute cmdlet mutes the default audio output device.
.LINK
Get-SoundVolume
.LINK
Set-SoundVolume
.LINK
Set-SoundUnmute
.LINK
https://github.com/jayharris/dotfiles-windows/
#>
[Audio]::Mute = $true
}
function Set-SoundUnmute {
<#
.SYNOPSIS
Unmote audio output.
.DESCRIPTION
The Set-SoundUnmute cmdlet unmutes the default audio output device.
.LINK
Get-SoundVolume
.LINK
Set-SoundVolume
.LINK
Set-SoundMute
.LINK
https://github.com/jayharris/dotfiles-windows/
#>
[Audio]::Mute = $false
}
# Reload the $env object from the registry
function Restore-Environment {
$locations = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
'HKCU:\Environment'
$locations | ForEach-Object {
$k = Get-Item $_
$k.GetValueNames() | ForEach-Object {
$name = $_
$value = $k.GetValue($_)
Set-Item -Path Env:\$name -Value $value
}
}
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
}
# Set a permanent Environment variable, and reload it into $env
function Set-SystemEnvironment([String] $variable, [String] $value) {
Set-ItemProperty "HKCU:\Environment" $variable $value
# Manually setting Registry entry. SetEnvironmentVariable is too slow because of blocking HWND_BROADCAST
#[System.Environment]::SetEnvironmentVariable("$variable", "$value","User")
Invoke-Expression "`$env:${variable} = `"$value`""
}
function Prepend-EnvPath([String]$path) { $env:PATH = $env:PATH + ";$path" }
function Prepend-EnvPathIfExists([String]$path) { if (Test-Path $path) { Prepend-EnvPath $path } }
function Append-EnvPath([String]$path) { $env:PATH = $env:PATH + ";$path" }
function Append-EnvPathIfExists([String]$path) { if (Test-Path $path) { Append-EnvPath $path } }
#endregion
#region Plugins
Import-Module ZLocation
#endregion
#region Chocolatey setup
# Import the Chocolatey Profile that contains the necessary code to enable
# tab-completions to function for `choco`.
# Be aware that if you are missing these lines from your profile, tab completion
# for `choco` will not function.
# See https://ch0.co/tab-completion for details.
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
}
#endregion
#region Prompt setup
#
# prompt: oh-my-posh
#
Append-EnvPathIfExists "$env:LOCALAPPDATA\Programs\oh-my-posh\bin\"
oh-my-posh init pwsh --config $env:LOCALAPPDATA\Programs\oh-my-posh\themes\powerlevel10k_lean.omp.json | Invoke-Expression
#endregion
#region Fuck setup
iex "$(thefuck --alias)"
#endregion