-
Notifications
You must be signed in to change notification settings - Fork 1
/
Microsoft.PowerShell_profile.ps1
93 lines (75 loc) · 3.46 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
# bash-like shortcuts
Set-PSReadlineKeyHandler -Key Tab -Function Complete
Set-PSReadLineKeyHandler -Key Alt+b -Function ShellBackwardWord
Set-PSReadLineKeyHandler -Key Alt+f -Function ShellForwardWord
Set-PSReadLineKeyHandler -Key Alt+B -Function SelectShellBackwardWord
Set-PSReadLineKeyHandler -Key Alt+F -Function SelectShellForwardWord
Set-PSReadLineKeyHandler -Key Ctrl+k -Function ForwardDeleteInput
set-alias npp "C:\Program Files\Notepad++\notepad++.exe"
set-alias grep select-string
function ga {git add $args}
function gd {git.exe diff $args}
function gds {git.exe diff --staged $args}
function gf {git.exe fetch $args}
function gg {git.exe hist $args}
function gs {git.exe status $args}
function manage{
poetry run python manage.py $args
}
function testall{
poetry run pytest --create-db --functional --unit --integration --disable-warnings $args && poetry run pytest --reuse-db --functional --unit --integration --cov --cov-report=xml --disable-warnings $args
}
function retest{
poetry run pytest --reuse-db --functional --unit --integration --cov --cov-report=xml --disable-warnings --last-failed $args
}
function apply{
[regex]::Replace((Get-Clipboard -Raw), "`r`n", "`n", "Singleline") | git apply --ignore-whitespace
}
oh-my-posh init pwsh --config ~/.dotfiles/ohmyposhv3.json | Invoke-Expression
# disable venv prompt
$env:VIRTUAL_ENV_DISABLE_PROMPT=1
Import-Module posh-git
Import-Module CompletionPredictor
# fix up/down in python shells https://github.com/microsoft/terminal/issues/2558#issuecomment-2069286909
py -c "import ctypes; ctypes.windll.kernel32.SetConsoleHistoryInfo(b'\x10\x00\x00\x00\x00\x02\x00\x00 \x00\x00\x00\x01\x00\x00\x00')"
# Don't add to history if short or common https://stackoverflow.com/a/52818502
$addToHistoryHandler = {
Param([string]$line)
if ($line.Length -le 3) {
return $false
}
if (@("exit","dir","ls","pwd","cd ..").Contains($line.ToLowerInvariant())) {
return $false
}
return $true
}
Set-PSReadlineOption -AddToHistoryHandler $addToHistoryHandler
# Remove history items with shift+del https://stackoverflow.com/a/77959050
Set-PSReadLineKeyHandler -Chord Shift+Delete -Description "Search through the history and remove lines starting with entered text" -ScriptBlock {
$in = ''
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref] $in, [ref] $null)
if ([string]::IsNullOrWhiteSpace($in)) {
return
}
$historyPath = (Get-PSReadLineOption).HistorySavePath
# only way to "refresh" the history in the current session is to clear it
[Microsoft.PowerShell.PSConsoleReadLine]::ClearHistory()
$content = [System.IO.File]::ReadAllLines($historyPath)
Clear-Content $historyPath
foreach ($line in $content) {
if ($line.StartsWith($in, [System.StringComparison]::InvariantCultureIgnoreCase)) {
continue
}
# and re-add it (excluding the line to remove)
[Microsoft.PowerShell.PSConsoleReadLine]::AddToHistory($line)
}
[Microsoft.PowerShell.PSConsoleReadLine]::DeleteLine()
}
# Define keyboard shortcut Alt-V to paste the current clipboard
# content as a verbatim here-string.
Set-PSReadLineKeyHandler 'alt+v' -ScriptBlock {
[Microsoft.PowerShell.PSConsoleReadLine]::Insert("@'`n`n'@")
foreach ($i in 1..3) { [Microsoft.PowerShell.PSConsoleReadLine]::BackwardChar() }
[Microsoft.PowerShell.PSConsoleReadLine]::Insert((Get-Clipboard -Raw))
foreach ($i in 1..3) { [Microsoft.PowerShell.PSConsoleReadLine]::ForwardChar() }
}