-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMicrosoft.PowerShell_profile.ps1
More file actions
98 lines (77 loc) · 3.54 KB
/
Microsoft.PowerShell_profile.ps1
File metadata and controls
98 lines (77 loc) · 3.54 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
# ============================================
# PowerShell Profile
# Colorful • Interactive • Safe • Fast
# ============================================
# ---------- Core Initialization ----------
# oh-my-posh (theme)
try {
oh-my-posh init pwsh --config "$env:USERPROFILE\Documents\PowerShell\theme\highContext.omp.json" | Invoke-Expression
}
catch {
Write-Host "⚠️ oh-my-posh not loaded" -ForegroundColor DarkYellow
}
# Initialize zoxide (smart cd)
try {
Invoke-Expression (& { (zoxide init powershell | Out-String) })
}
catch {
Write-Host "⚠️ zoxide not loaded" -ForegroundColor DarkYellow
}
# ---------- Module Loading ----------
# Load modules quietly if present, show which succeed
$modules = @(
# Visual / Prompt Enhancements
'Terminal-Icons', # Adds file/folder icons to Get-ChildItem
'posh-git', # Git status info in prompt
'Get-ChildItemColor', # LS-like command with colors
# System / Windows
'PSWindowsUpdate', # Manage Windows Updates from PowerShell
'BurntToast', # Send Windows toast notifications
'PSScriptAnalyzer', # Lint/analyze PowerShell scripts for issues
# Navigation / Productivity
'PSFzf', # Fuzzy search for history, files, commands
'PSReadLine', # Enhanced command editing & history (usually built-in)
# Networking / Remote
'Posh-SSH' # SSH, SCP, SFTP support directly in PowerShell
)
foreach ($module in $modules) {
if (-not (Get-Module -ListAvailable -Name $module)) {
Install-Module $module -Scope CurrentUser -Force
}
Import-Module $module -ErrorAction SilentlyContinue
Write-Host "✅ $module loaded" -ForegroundColor Green
}
# ---------- PSReadLine Configuration ----------
# Modern + Useful PSReadLine Config
Set-PSReadLineOption -PredictionSource HistoryAndPlugin
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineOption -EditMode Windows
Set-PSReadLineOption -MaximumHistoryCount 1000
#Set-PSReadLineOption -HistorySavePath "$env:USERPROFILE\Documents\PowerShell\txt files\PSReadLineHistory.txt"
Set-PSReadLineOption -Colors @{ "InlinePrediction" = "$([char]27)[90m" }
# Key bindings
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
Set-PSReadLineKeyHandler -Key Ctrl+r -Function ReverseSearchHistory
Set-PSReadLineKeyHandler -Key Ctrl+w -Function BackwardDeleteWord
#univrsal helpers for other functions to run repeated things
Import-Module "$HOME\Documents\PowerShell\EasyModules\Helpers\helpers.psm1"
# ---------- Load Custom Functions ----------
$easyFuncsPath = "$env:USERPROFILE\Documents\PowerShell\EasyModules"
if (Test-Path $easyFuncsPath) {
$files = Get-ChildItem -Path $easyFuncsPath -Filter *.ps1 -File
foreach ($file in $files) {
try {
$time = Measure-Command { . $file.FullName }
Write-Host "✅ $($file.BaseName) loaded in $([math]::Round($time.TotalMilliseconds,2)) ms" -ForegroundColor Green
}
catch {
Write-Host "❌ Failed to load $($file.Name): $_" -ForegroundColor Red
}
}
}
else {
Write-Host "⚠️ EasyModules folder not found at: $easyFuncsPath" -ForegroundColor Yellow
}
# ---------- Aliases ----------
# Keep minimal and DRY