-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.ps1
139 lines (110 loc) · 3.7 KB
/
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
# Disable blinking cursor if running in Windows Terminal
if (Test-Path env:WT_SESSION)
{
Write-Host -NoNewline "`e[2 q"
}
# Set character encoding to UTF-8 for all commands that support the -Encoding
# parameter. As of PowerShell Core, UTF-8 is the default encoding.
if ($PSVersionTable.PSVersion.Major -le 5)
{
$PSDefaultParameterValues['*:Encoding'] = 'utf8'
}
$PSDefaultParameterValues += @{
'Invoke-WebRequest:UseBasicParsing' = $True
}
# Set default editor to open text files with
$Editor = if (Test-Path env:EDITOR) { $env:EDITOR } else { 'notepad' }
# Make Powershell behave similarly to Bash
if ($host.Name -eq 'ConsoleHost') {
Import-Module PSReadLine
Set-PSReadLineOption -EditMode Emacs
Set-PSReadlineOption -BellStyle Visual
Set-PSReadlineOption -HistorySearchCursorMovesToEnd
Set-PSReadlineOption -HistoryNoDuplicates
Set-PSReadlineKeyHandler -Key Tab -Function Complete
}
function private:Source-OptionalFile ([string] $targetFile) {
if (Test-Path $targetFile) {
. $targetFile
}
}
# Import posh-git module
Import-Module posh-git
# Add a trailing new line character to the prompt
$GitPromptSettings.DefaultPromptBeforeSuffix.Text = '`n'
# Print the branch name at the start of the prompt, before the current directory
$GitPromptSettings.DefaultPromptWriteStatusFirst = $True
# Show number of stash entries
$GitPromptSettings.EnableStashStatus = $True
# Import ZLocation module to easily jump around within directories
Import-Module ZLocation
# Docker
if (Get-Command docker -ErrorAction SilentlyContinue) {
Import-Module DockerCompletion
}
# Kubernetes
if (Get-Command kubectl -ErrorAction SilentlyContinue) {
Set-Alias k -Value kubectl
kubectl completion powershell | Out-String | Invoke-Expression
}
# Import posh-vcpkg if present
Import-Module "$env:VCPKG_ROOT\scripts\posh-vcpkg" -ErrorAction SilentlyContinue
if ($PSVersionTable.PSVersion.Major -le 5)
{
Remove-Item Alias:curl -ErrorAction SilentlyContinue
Remove-Item Alias:wget -ErrorAction SilentlyContinue
}
# Alias common parameters for Remove-Item
function Nuke-Item {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseApprovedVerbs', '')]
param()
Remove-Item -Recurse -Force @Args
}
# Create an alias to make it easier to open text files
function Edit-File {
&"$Editor" @Args
}
# Create an alias to make it easier to open the Powershell configuration
function Edit-PowerShell {
Edit-File @Args "$($Profile.CurrentUserAllHosts)"
}
# Open Neovim's config file
function Edit-Neovim {
Edit-File @Args "$env:LOCALAPPDATA\nvim\init.vim"
}
# Edit hosts file
function Edit-Hosts {
Edit-File @Args $env:SystemRoot\System32\drivers\etc\hosts
}
# Update all pip packages
function Update-PipLocalRepository {
pip list --outdated --format freeze | ForEach-Object { pip.exe install -U $_.Substring(0, $_.IndexOf('=')) }
}
# Update all Neovim plugins
function Update-NeovimPlugins {
nvim -c PlugUpgrade -c quitall && nvim -c PlugUpdate -c quitall
}
# Find files by name recursively
function Find-File {
Get-ChildItem -Force -Recurse -ErrorAction SilentlyContinue @Args
}
# Quickly open all files with conflicts in the editor
function Resolve-MergeConflicts {
$FilesWithConflicts = (git diff --name-only --diff-filter=U | Get-Unique)
if ($FilesWithConflicts) {
&"$Editor" @FilesWithConflicts
} else {
Write-Output 'There are currently no files with conflicts.'
}
}
# Source ripgrep completion file
Source-OptionalFile "$HOME\scoop\apps\ripgrep\current\complete\_rg.ps1"
# Source rustup completions
Source-OptionalFile "$PSScriptRoot\_rustup.ps1"
# Get weather report
function Get-Weather {
curl.exe 'wttr.in'
}
function Start-DeveloperPowerShell {
& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\Community\Common7\Tools\Launch-VsDevShell.ps1"
}