-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMicrosoft.PowerShell_profile.ps1
More file actions
162 lines (131 loc) · 5.71 KB
/
Microsoft.PowerShell_profile.ps1
File metadata and controls
162 lines (131 loc) · 5.71 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
$env:PYTHONIOENCODING="utf-8"
# ---------------------------------------------------------------------------- #
# General config #
# ---------------------------------------------------------------------------- #
$ShowAsciiArt = $true
# ---------------------------------------------------------------------------- #
# Modules #
# ---------------------------------------------------------------------------- #
Import-Module -Name Terminal-Icons
Set-PSReadLineOption -PredictionSource HistoryAndPlugin -PredictionViewStyle ListView
# ---------------------------------------------------------------------------- #
# Scripts #
# ---------------------------------------------------------------------------- #
#winfetch
# ---------------------------------------------------------------------------- #
# Aliases #
# ---------------------------------------------------------------------------- #
# ---------------------------------------------------------------------------- #
# Functions #
# ---------------------------------------------------------------------------- #
function dotfiles {
git --git-dir=$HOME/.dotfiles --work-tree=$HOME $args
}
function dotfiles-status { dotfiles status }
function dotfiles-add { dotfiles add $args; dotfiles status }
function dotfiles-commit { dotfiles commit -m $args }
function dotfiles-push { dotfiles push origin main }
function dotfiles-pull { dotfiles pull origin main }
function dotfiles-diff { dotfiles diff }
function dotfiles-track {
param([string]$File)
$FullPath = (Resolve-Path $File).Path
$RelativePath = $FullPath.Replace("$HOME/", "").Replace("$HOME\", "")
Write-Host "Tracking: $RelativePath" -ForegroundColor Green
dotfiles add $RelativePath
dotfiles status
}
function nav {
param(
[Parameter(Mandatory=$true)]
[string]$Path
)
if (Test-Path $Path) {
cd $Path
ls
} else {
Write-Host "❌ Path not found: $Path" -ForegroundColor Red
}
}
function Set-Symlink {
param(
[Parameter(Mandatory = $true)]
[string]$Destination, # Path where the symlink will be created
[Parameter(Mandatory = $true)]
[string]$Source # Path the symlink will point to
)
# 1. Resolve source path
try {
$ResolvedSource = Resolve-Path -LiteralPath $Source -ErrorAction Stop
}
catch {
Write-Host "❌ Error: Source path '$Source' not found or inaccessible." -ForegroundColor Red
return
}
# 2. Check if destination exists
if (Test-Path -LiteralPath $Destination) {
Write-Host "⚠️ Destination '$Destination' already exists." -ForegroundColor Yellow
$confirmation = Read-Host "Do you want to replace it with a symlink? Type 'YES' to proceed"
if ($confirmation -ne 'YES') {
Write-Host "❌ Operation cancelled." -ForegroundColor Red
return
}
else {
# Attempt to remove only if confirmed
try {
Get-Item -LiteralPath $Destination -ErrorAction SilentlyContinue | Remove-Item -Recurse -Force -ErrorAction Stop
Write-Host "ℹ️ Existing item removed." -ForegroundColor Green
}
catch {
Write-Host "❌ Failed to remove existing item. Aborting." -ForegroundColor Red
return
}
}
}
# 3. Determine if source is a file or directory
$itemType = if ((Get-Item -LiteralPath $ResolvedSource.Path).PSIsContainer) { 'Directory' } else { 'File' }
# 4. Create the symlink
try {
Write-Host "🔗 Creating symlink: '$Destination' -> '$($ResolvedSource.Path)'" -ForegroundColor Green
New-Item -ItemType SymbolicLink -Path $Destination -Target $ResolvedSource.Path -Force | Out-Null
}
catch {
Write-Host "❌ Failed to create symbolic link at '$Destination'." -ForegroundColor Red
Write-Host " Possible reason: run PowerShell as Administrator for symlinks." -ForegroundColor Red
}
}
# ------------------------------- yazi function ------------------------------ #
function y {
$tmp = (New-TemporaryFile).FullName
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 (Resolve-Path -LiteralPath $cwd).Path
}
Remove-Item -Path $tmp
}
# ---------------------------------------------------------------------------- #
# ohmyposh #
# ---------------------------------------------------------------------------- #
oh-my-posh init pwsh --config '~/.config/amro-jaysum.omp.json' | Invoke-Expression
# ---------------------------------------------------------------------------- #
# Custom ASCII Art Welcome Message #
# ---------------------------------------------------------------------------- #
$asciiArt = @"
Welcome back,
┏┓┏━┓╻ ╻┏━┓╻ ╻┏┳┓
┃┣━┫┗┳┛┗━┓┃ ┃┃┃┃
┗━┛╹ ╹ ╹ ┗━┛┗━┛╹ ╹
"@
<# centers the ASCII art based on console width
$consoleWidth = [Console]::WindowWidth
$lines = $asciiArt -split "`n"
foreach ($line in $lines) {
$padding = " " * [Math]::Max(0, $consoleWidth - $line.Length)
Write-Host "$padding$line"
}
#>
# TOGGLE DISPLAY
If ($ShowAsciiArt) {
Write-Host "$asciiArt"
}