-
Notifications
You must be signed in to change notification settings - Fork 39
/
defaults.ps1
66 lines (53 loc) · 1.91 KB
/
defaults.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
# Proper history etc
Import-Module PSReadLine
# Produce UTF-8 by default
# https://news.ycombinator.com/item?id=12991690
$PSDefaultParameterValues["Out-File:Encoding"] = "utf8"
# https://technet.microsoft.com/en-us/magazine/hh241048.aspx
$MaximumHistoryCount = 10000;
Set-Alias trash Remove-ItemSafely
function open($file) {
invoke-item $file
}
function explorer {
explorer.exe .
}
function edge {
# Old Edge
# start microsoft-edge:
#
# New Chromioum Edge
& "${env:ProgramFiles(x86)}\Microsoft\Edge Dev\Application\msedge.exe"
}
function settings {
start-process ms-setttings:
}
# Oddly, Powershell doesn't have an inbuilt variable for the documents directory. So let's make one:
# From https://stackoverflow.com/questions/3492920/is-there-a-system-defined-environment-variable-for-documents-directory
$env:DOCUMENTS = [Environment]::GetFolderPath("mydocuments")
# PS comes preset with 'HKLM' and 'HKCU' drives but is missing HKCR
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null
# Truncate homedir to ~
function limit-HomeDirectory($Path) {
$Path.Replace("$home", "~")
}
# Must be called 'prompt' to be used by pwsh
# https://github.com/gummesson/kapow/blob/master/themes/bashlet.ps1
function prompt {
$realLASTEXITCODE = $LASTEXITCODE
Write-Host $(limit-HomeDirectory("$pwd")) -ForegroundColor Yellow -NoNewline
Write-Host " $" -NoNewline
$global:LASTEXITCODE = $realLASTEXITCODE
Return " "
}
# Make $lastObject save the last object output
# From http://get-powershell.com/post/2008/06/25/Stuffing-the-output-of-the-last-command-into-an-automatic-variable.aspx
function out-default {
$input | Tee-Object -var global:lastobject | Microsoft.PowerShell.Core\out-default
}
# If you prefer oh-my-posh
# Import-Module posh-git
# Import-Module oh-my-posh
function rename-extension($newExtension){
Rename-Item -NewName { [System.IO.Path]::ChangeExtension($_.Name, $newExtension) }
}