-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMicrosoft.PowerShell_profile.ps1
More file actions
194 lines (152 loc) · 5.56 KB
/
Microsoft.PowerShell_profile.ps1
File metadata and controls
194 lines (152 loc) · 5.56 KB
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
### PowerShell Profile
### Version 2.0 - Refactored by Clue-ess-coder ƒÖé
$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
function prompt {
if ($isAdmin) { "[" + (Get-Location) + "] # " } else { "[" + (Get-Location) + "] $ " }
}
#opt-out of telemetry before doing anything, only if PowerShell is run as admin
if ([bool]([System.Security.Principal.WindowsIdentity]::GetCurrent()).IsSystem) {
[System.Environment]::SetEnvironmentVariable('POWERSHELL_TELEMETRY_OPTOUT', 'true', [System.EnvironmentVariableTarget]::Machine)
}
$adminSuffix = if ($isAdmin) { " [ADMIN]" } else { "" }
$Host.UI.RawUI.WindowTitle = "PowerShell {0}$adminSuffix" -f $PSVersionTable.PSVersion.ToString()
# Some Random Shenanigans
function Clear-Cache {
# add clear cache logic here
Write-Host "Clearing cache..." -ForegroundColor Cyan
# Clear Windows Prefetch
Write-Host "Clearing Windows Prefetch..." -ForegroundColor Yellow
Remove-Item -Path "$env:SystemRoot\Prefetch\*" -Force -ErrorAction SilentlyContinue
# Clear Windows Temp
Write-Host "Clearing Windows Temp..." -ForegroundColor Yellow
Remove-Item -Path "$env:SystemRoot\Temp\*" -Recurse -Force -ErrorAction SilentlyContinue
# Clear User Temp
Write-Host "Clearing User Temp..." -ForegroundColor Yellow
Remove-Item -Path "$env:TEMP\*" -Recurse -Force -ErrorAction SilentlyContinue
# Clear Internet Explorer Cache
Write-Host "Clearing Internet Explorer Cache..." -ForegroundColor Yellow
Remove-Item -Path "$env:LOCALAPPDATA\Microsoft\Windows\INetCache\*" -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "Cache clearing completed." -ForegroundColor Green
}
# Utility Functions
function Test-CommandExists {
param($command)
$exists = $null -ne (Get-Command $command -ErrorAction SilentlyContinue)
return $exists
}
# Editor Configuration
Set-Alias -Name vim -Value "nvim"
function Edit-Profile {
vim $PROFILE
}
#################################################
# New Additions
#################################################
# Network Utilities
function Get-PubIP { (Invoke-WebRequest http://ifconfig.me/ip).Content }
# Open WinUtil full-release
function winutil {
irm https://christitus.com/win | iex
}
# System Utilities
function admin {
if ($args.Count -gt 0) {
$argList = $args -join ' '
Start-Process wt -Verb runAs -ArgumentList "pwsh.exe -NoExit -Command $argList"
} else {
Start-Process wt -Verb runAs
}
}
Set-Alias -Name su -Value admin
function touch($file) { "" | Out-File $file -Encoding ASCII }
### Profile Management
function Reload-Profile {
& $PROFILE
}
function grep($regex, $dir) {
if ( $dir ) {
Get-ChildItem $dir | select-string $regex
return
}
$input | select-string $regex
}
function which($name) {
Get-Command $name | Select-Object -ExpandProperty Definition
}
function head {
param($Path, $n = 10)
Get-Content $Path -Head $n
}
function tail {
param($Path, $n = 10)
Get-Content $Path -Tail $n
}
# Directory Management
function mkcd { param($dir) mkdir $dir -Force; Set-Location $dir }
# Enhanced Listing
function la { Get-ChildItem -Path . -Force | Format-Table -AutoSize }
function ll { Get-ChildItem -Path . -Force -Hidden | Format-Table -AutoSize }
# Networking Utilities
function flushdns {
Clear-DnsClientCache
Write-Host "DNS cache flushed." -ForegroundColor Green
}
# Clipboard Utilities
# Enhanced PowerShell Experience
# Set-PSReadLineOption -Colors @{
# Command = 'Yellow'
# Parameter = 'Green'
# String = 'DarkCyan'
# }
function egc {
vim "C:\Users\Abdul-Hameed\.glzr\glazewm\config.yaml"
}
function ezc {
vim "C:\Users\Abdul-Hameed\.glzr\zebar\config.yaml"
}
function bm {
zoxide add .
}
function hugo-dev {
hugo server -D --disableFastRender --noHTTPCache --renderToMemory --gc --navigateToChanged
}
Set-Alias -Name serve -Value hugo-dev
function compile-pdf {
xelatex --shell-escape main.tex
}
function Clear-History {
set-content -Path ((Get-PSReadLineOption).HistorySavePath) -Value "hello"
}
function y {
$tmp = [System.IO.Path]::GetTempFileName()
yazi $args --cwd-file="$tmp"
$cwd = Get-Content -Path $tmp -Encoding UTF8
if (-not [String]::IsNullOrEmpty($cwd) -and $cwd -ne $PWD.Path) {
Set-Location -LiteralPath ([System.IO.Path]::GetFullPath($cwd))
}
Remove-Item -Path $tmp
}
function Get-ModifiedDate {
param([string]$Path)
(Get-Item $Path).LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")
}
Set-Alias gmd Get-ModifiedDate
# function init {
# Import-Module -Name Terminal-Icons
#
# oh-my-posh init pwsh --config 'C:\Users\Abdul-Hameed\AppData\Local\Programs\oh-my-posh\themes\tonybaloney.omp.json' | Invoke-Expression
# }
Import-Module -Name Terminal-Icons -ErrorAction SilentlyContinue
Set-PSReadLineOption -EditMode Vi
# Set-PSReadLineOption -PredictionSource HistoryAndPlugin
# Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineOption -BellStyle None
Set-PSReadLineKeyHandler -Chord "Alt+j" -Function ViCommandMode
Set-PSReadLineKeyHandler -Chord "Alt+l" -Function AcceptSuggestion
Set-PSReadlineKeyHandler -Key Enter -Function ValidateAndAcceptLine
## carapace Shenanigans
$env:CARAPACE_BRIDGES = 'zsh,fish,bash,inshellisense' # optional
Set-PSReadLineOption -Colors @{ "Selection" = "`e[7m" }
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
carapace _carapace | Out-String | Invoke-Expression
Invoke-Expression (& { (zoxide init --cmd cd powershell | Out-String) })