-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMicrosoft.PowerShell_profile.ps1
165 lines (133 loc) · 4.14 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
# .__
# _____ | | POWERSHELL 7 SETUP
# \__ \ | | Abdul Hakim (alarwasyi98)
# / __ \| |__ https://github.com/alarwasyi98
# (____ /____/
# \/
### ENVIRONMENT VARIABLES ###
Set-Item -Force -Path "ENV:CONFIG_HOME" -Value $HOME\.config
Set-Item -Force -Path "ENV:STARSHIP_CONFIG" -Value $HOME\.config\starship.toml
# Utility Functions
function Test-CommandExists {
param($command)
$exists = $null -ne (Get-Command $command -ErrorAction SilentlyContinue)
return $exists
}
# Editor Configuration
$EDITOR = if (Test-CommandExists nvim) { 'nvim' }
elseif (Test-CommandExists pvim) { 'pvim' }
elseif (Test-CommandExists vim) { 'vim' }
elseif (Test-CommandExists vi) { 'vi' }
elseif (Test-CommandExists code) { 'code' }
elseif (Test-CommandExists notepad++) { 'notepad++' }
elseif (Test-CommandExists sublime_text) { 'sublime_text' }
else { 'notepad' }
# Exporting chocolatey profile to enable tab-completion
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
}
### ALIASES ###
Set-Alias -Name tt -Value tree
Set-Alias -Name ll -Value ls
Set-Alias -Name vim -Value $EDITOR
Set-Alias -Name vi -Value nvim
Set-Alias -Name cat -Value bat
Set-Alias -Name h -Value Get-History
### HANDY ALIASES ###
Set-Alias -Name ep -Value Edit-Profile
Set-Alias -Name sedit -Value Edit-Starship
# Set UNIX-like aliases for the admin command, See function below
# so sudo <command> will run the command with elevated rights.
Set-Alias -Name su -Value admin
### FUNCTIONS ###
# pwsh
Function Edit-Profile { vim $PROFILE }
# starship
Function Edit-Starship { vim $STARSHIP_CONFIG }
# nvim
Function Edit-Nvim { vim $ENV:LOCALAPPDATA\nvim }
# Git
Function gs { git status }
Function ga { git add . }
Function gcm { param($m) git commit -m "$m" }
Function gp { git push }
Function g { z Github }
Function gcl { git clone "$args" }
Function gcom {
git add .
git commit -m "$args"
}
Function lazyg {
git add .
git commit -m "$args"
git push
}
# fzf
Function bfzf {
fzf --preview="bat --decorations=always --color=always {}"
}
Function fzfvim {
nvim (fzf --preview="bat --decorations=always --color=always {}")
}
### SPECIAL FUNCTIONS ###
# Reload PowerShell Profiles for All Users
Function Update-Profile {
# Memuat ulang profil PowerShell
. $PROFILE
Write-Output "Profile Reloaded"
}
# Create New-Item
Function touch($file) { "" | Out-File $file -Encoding ASCII }
# Locate file quickly
Function ff ($name) {
Get-ChildItem -recurse -filter "*${name}*" -ErrorAction SilentlyContinue | ForEach-Object {
Write-Output "$($_.FullName)"
}
}
# Extract ZIP File
Function unzip ($file) {
Write-Output("Extracting", $file, "to", $pwd)
$fullFile = Get-ChildItem -Path $pwd -Filter $file | ForEach-Object { $_.FullName }
Expand-Archive -Path $fullFile -DestinationPath $pwd
}
# Print command location
Function which {
param (
[Parameter(Mandatory = $true, Position = 0)]
[string]$command
)
$result = Get-Command $command -ErrorAction SilentlyContinue
if ($result) {
$result.Source
}
else {
Write-Host "${command} not found"
}
}
# Run as Administrator
Function admin {
if ($args.Count -gt 0) {
$argList = "& '$args'"
Start-Process wt -Verb runAs -ArgumentList "pwsh.exe -NoExit -Command $argList"
}
else {
Start-Process wt -Verb runAs
}
}
### MODULES IMPORTER ###
# Terminal-Icons
Import-Module Terminal-Icons
# PSReadline; fish-like capability
Set-PSReadlineKeyHandler -Key Tab -Function Complete
Set-PSReadlineOption -PredictionViewStyle InlineView
Set-PsReadlineOption -PredictionSource History
# Command Not Found (PowerToys)
Import-Module -Name Microsoft.WinGet.CommandNotFound
### INVOCATIONS ###
# colorscripts
Show-ColorScript -Name alpha
# starship
Invoke-Expression (&starship init powershell)
# zoxide
Invoke-Expression (& { (zoxide init powershell | Out-String) })