-
Notifications
You must be signed in to change notification settings - Fork 0
/
Microsoft.PowerShell_profile.ps1
executable file
·106 lines (84 loc) · 3.47 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
# OS-agnostic setup. Manually run:
# Install-Module Pester -Scope CurrentUser
# Install-Module posh-git -Scope CurrentUser
# Install-Module powershell-yaml -Scope CurrentUser
# Install-Module PowerShellForGitHub -Scope CurrentUser
# Default handler excludes lines like /password/ -- Instead use bash pattern of excluding lines with leading space
# https://github.com/PowerShell/PSReadLine/blob/bc485e0208d5dbf44c3d92a1dec9d466c41afc36/PSReadLine/History.cs#L116
Set-PSReadlineOption -AddToHistoryHandler { param ($line) -not $line.StartsWith(' ') }
Set-PSReadlineOption -MaximumHistoryCount 32767
$PSNativeCommandUseErrorActionPreference = $true
function .. { cd .. }
function ... { cd ..\.. }
function .... { cd ..\..\.. }
function ..... { cd ..\..\..\.. }
function ...... { cd ..\..\..\..\.. }
function pushtmp {
$tmp = Join-Path "Temp:" "DEL-$(Get-Date -Format "yyyyMMdd-HH-mm-ss.ff")"
New-Item -ItemType Directory -Path $tmp | Out-Null
Push-Location $tmp
}
if (Get-Command python.exe -errorAction SilentlyContinue) {
# Windows pyenv doesn't shim `python3`
Set-Alias py python
Set-Alias python3 python
} else {
Set-Alias py python3
Set-Alias python python3
}
# TODO loop over PY files with '# /// script' and create the functions?
# like http://huddledmasses.org/powershell-power-user-tips-bash-style-alias-command
# Can't use Set-Alias because aliases in pwsh don't support arguments!
function gpx { pipx run (Join-Path $PSScriptRoot gpx.py) @args }
function stravart { pipx run (Join-Path $PSScriptRoot stravart.py) @args }
function ipy {
py -m IPython @args
}
$ENV:PYENV_SHELL = "pwsh"
function wh($ex) {
$cmds = gcm $ex -All
foreach ($cmd in $cmds) {
$cmd
if ($cmd.CommandType -ne 'Alias') { continue }
wh $cmd.ResolvedCommand
}
}
function export($s) {
# TODO this doesn't work if value has '=' in it
$n, $v = $s -split '='
Set-Item "env:$n" $v
}
function Source-Anything($path) {
$tempFile = (New-TemporaryFile).FullName + ".ps1"
Copy-Item $path $tempFile
. $tempFile
}
# MAYBE some magic 'not interactive pw so skip the theme stuff???' and return
Set-PSReadlineOption -BellStyle Visual
if (gcm gh -all -ErrorAction SilentlyContinue) {
Invoke-Expression -Command $(gh completion -s powershell | Out-String)
}
New-Alias time Measure-Command
function timeit($func) { 0..3 | % { (time $func).TotalMilliseconds } }
If (Test-Path Alias:md) { Remove-Item Alias:md }
function md($dir) { mkdir -p $dir | out-null; cd $dir }
function PrependPATH($s) {
$s = (Resolve-Path $s).Path # https://github.com/ansible/ansible-lint/issues/2688#issuecomment-1944316451
if (($ENV:PATH -split [IO.Path]::PathSeparator) -contains $s) { return }
$env:PATH = $s + [IO.Path]::PathSeparator + $env:PATH
}
function AppendPATH($s) {
$s = (Resolve-Path $s).Path
if (($ENV:PATH -split [IO.Path]::PathSeparator) -contains $s) { return }
$env:PATH = $env:PATH + [IO.Path]::PathSeparator + $s
}
PrependPATH $PSScriptRoot
AppendPATH "." # Useful, but don't cd into untrusted folders!
if (gcm Set-PoshPrompt -ErrorAction SilentlyContinue) {
Write-Warning "Stop using pwsh module! https://ohmyposh.dev/docs/migrating"
}
if (gcm oh-my-posh -ErrorAction SilentlyContinue) {
$env:VIRTUAL_ENV_DISABLE_PROMPT = "yes" # Skip venv prompt, because custom prompt sets it
Import-Module posh-git
oh-my-posh init pwsh --config (Join-Path $PSScriptRoot .go-my-posh.yaml) | Invoke-Expression
}