-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_win.ps1
More file actions
404 lines (349 loc) · 13.2 KB
/
setup_win.ps1
File metadata and controls
404 lines (349 loc) · 13.2 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
# NOTE:
# _.-;;-._
# '-..-'| || |
# '-..-'|_.-;;-._|
# '-..-'| || |
# '-..-'|_.-''-._|
<#
.SYNOPSIS
's Windows Setup Manifest
#>
# ------------------------------------------------------
# 1. SELF-ELEVATION & EXECUTION POLICY
# ------------------------------------------------------
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
$isAdmin = $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if ($isAdmin)
{
Write-Host ":: Running as Administrator." -ForegroundColor Cyan
if ((Get-ExecutionPolicy) -ne 'Bypass')
{
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force -ErrorAction SilentlyContinue
}
} else
{
Write-Host ":: Not running as Administrator." -ForegroundColor Yellow
Write-Host ":: Attempting to request Admin privileges..." -ForegroundColor Gray
try
{
# Relaunch as Admin with Bypass policy
Start-Process PowerShell -Verb RunAs -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$($MyInvocation.MyCommand.Path)`"" -ErrorAction Stop
exit
} catch
{
Write-Warning ":: Admin privileges denied."
Write-Host ":: Continuing as Standard User..." -ForegroundColor Green
}
}
# ------------------------------------------------------
# 2. WINGET (System Apps)
# ------------------------------------------------------
Write-Host ":: Checking System Apps..." -ForegroundColor Green
Write-Host ":: Updating Winget Sources..." -ForegroundColor Gray
winget source update --disable-interactivity
try
{
winget install --id Microsoft.PowerShell -e --scope user --accept-package-agreements --accept-source-agreements
winget install --id Microsoft.WindowsTerminal -e --scope user --accept-package-agreements --accept-source-agreements
winget install --id Microsoft.PowerToys -e --scope user --accept-package-agreements --accept-source-agreements
# Raycast
winget install --id 9PFXXSHC64H3 -e --scope user --accept-package-agreements --accept-source-agreements
if ($isAdmin)
{
winget install --id Microsoft.VisualStudio.2022.BuildTools --override "--passive --wait --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended" --accept-package-agreements --accept-source-agreements
} else
{
Write-Warning ":: Skipping Visual Studio Build Tools (requires Administrator privileges)."
}
} catch
{
Write-Warning "Winget failed. Ensure App Installer is updated in the MS Store."
}
# ------------------------------------------------------
# 3. SCOOP (Package Manager)
# ------------------------------------------------------
if (-not (Test-Path "$env:USERPROFILE\scoop"))
{
Write-Host ":: Installing Scoop..." -ForegroundColor Green
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression
} else
{
Write-Host ":: Scoop is already installed." -ForegroundColor Green
}
# Add buckets
scoop install git
scoop bucket add extras
scoop bucket add versions
scoop bucket add nerd-fonts
scoop update
# ------------------------------------------------------
# 4. BOOTSTRAP DEPENDENCIES
# ------------------------------------------------------
# We need these immediately for the script to function
$bootstrapApps = @("mise", "innounp-unicode", "psfzf", "psreadline", "terminal-icons")
Write-Host ":: Installing Bootstrap Dependencies..." -ForegroundColor Green
foreach ($app in $bootstrapApps)
{
if (-not (Get-Command $app -ErrorAction SilentlyContinue))
{
scoop install $app
}
}
# ------------------------------------------------------
# 5. INSTALL MISE
# ------------------------------------------------------
if (-not (Get-Command mise -ErrorAction SilentlyContinue))
{
Write-Host ":: Installing Mise..." -ForegroundColor Green
scoop install mise
}
# ACTIVATE MISE FOR THIS SESSION
# Critical: Allows us to use 'mise use' and access installed tools immediately
$env:MISE_YES = 1
Invoke-Expression "$(mise activate pwsh)"
mise use -g age@latest chezmoi@latest github-cli@latest
# ------------------------------------------------------
# 6. DOTFILES (Chezmoi)
# ------------------------------------------------------
Write-Host ":: Migrating dotfiles..." -ForegroundColor Green
Read-Host ":: Please put key.txt in ~/.config/. Press Enter to continue"
# Ensure we are in the home directory
Set-Location $env:USERPROFILE
if (-not (Test-Path "$env:USERPROFILE\.local\share\chezmoi"))
{
chezmoi init --apply https://github.com/joncrangle/.dotfiles.git
} else
{
chezmoi apply
}
# ------------------------------------------------------
# 7. INSTALL PACKAGES
# ------------------------------------------------------
# SYSTEM / GUI TOOLS (Scoop)
$scoopApps = @(
"7zip", "bruno", "btop", "chafa", "curl", "dbeaver", "diffutils", "ffmpeg", "ghostscript", "glazewm",
"gzip", "imagemagick", "IosevkaTerm-NF", "JetBrainsMono-NF", "krita", "lua", "luarocks", "make", "Maple-Mono",
"Meslo-NF", "mingw-winlibs", "obsidian", "podman", "poppler", "python", "rustup-msvc", "sqlite", "topgrade", "unar",
"unzip", "vlc", "vcredist2022", "wezterm-nightly", "win32yank", "wget", "zebar", "zed", "zoom"
)
Write-Host ":: Installing System Apps via Scoop..." -ForegroundColor Green
scoop install $scoopApps
# DEV TOOLS (Mise)
# This uses the config.toml pulled down by chezmoi
Write-Host ":: Installing Dev Tools via Mise..." -ForegroundColor Green
mise lock
mise install --yes
# ------------------------------------------------------
# 8. CONFIGURATION & TWEAKS
# ------------------------------------------------------
# --- IDENTITY PROMPT ---
$DefaultName = "jonathancrangle"
$DefaultEmail = "94425204+joncrangle@users.noreply.github.com"
Write-Host ":: Configuring User Identity..." -ForegroundColor Green
$GitName = gum input --header "Git User Name" --value $DefaultName
$GitEmail = gum input --header "Git Email" --value $DefaultEmail
Write-Host ":: Configuring Git..." -ForegroundColor Green
git config --global credential.helper manager
git config --global user.name "$GitName"
git config --global user.email "$GitEmail"
if (gum confirm "Generate new SSH key for GitHub?")
{
$sshDir = "$env:USERPROFILE\.ssh"
if (-not (Test-Path $sshDir))
{ New-Item -Type Directory $sshDir -Force
}
ssh-keygen -t ed25519 -C "$GitEmail" -f "$sshDir\id_ed25519"
}
# Github Auth
Write-Host ":: Authenticating GitHub..." -ForegroundColor Green
if (-not (gh auth status))
{
gh auth login --web
}
# Fonts
Write-Host ":: Installing Fonts..." -ForegroundColor Green
$fontSource = "$env:USERPROFILE\.config\fonts"
$fontDest = "$env:LOCALAPPDATA\Microsoft\Windows\Fonts"
if (Test-Path $fontSource)
{
if (-not (Test-Path $fontDest))
{ New-Item -Type Directory $fontDest -Force
}
Get-ChildItem $fontSource -Include *.ttf,*.otf -Recurse | ForEach-Object {
$destFile = Join-Path $fontDest $_.Name
if (-not (Test-Path $destFile))
{
Copy-Item $_.FullName $destFile
New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" -Name $_.Name -Value $_.Name -Force
}
}
}
# Windows Terminal Settings
Write-Host ":: Configuring Windows Terminal..." -ForegroundColor Green
$wtPath = "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json"
$wtSource = "$env:USERPROFILE\.config\windows-terminal\settings.json"
if (Test-Path $wtSource)
{
Copy-Item $wtSource $wtPath -Force
}
# Yazi / Bat / JJ Config
# (Assuming Mise installed them, we just configure)
if (Get-Command bat -ErrorAction SilentlyContinue)
{ bat cache --build
}
if (Get-Command ya -ErrorAction SilentlyContinue)
{ ya pkg install; ya pkg update
}
if (Get-Command jj -ErrorAction SilentlyContinue)
{
jj config set --user user.name "$GitName"
jj config set --user user.email "$GitEmail"
@"
`n[ui]
pager = "delta"
editor = "nvim"
diff-editor = ["nvim", "-c", "DiffEditor `$left `$right `$output"]
[ui.diff]
format = "git"
"@ | Out-File -Append -FilePath (jj config path --user) -Encoding utf8
}
# Rust Setup (Mise installed rustup, we config it)
if (Get-Command rustup -ErrorAction SilentlyContinue)
{
rustup default stable
rustup update
}
# Python Registry Fix (PEP 514)
# This allows external tools to find the Mise-installed Python
$pyReg = "$env:USERPROFILE\scoop\apps\python\current\install-pep-514.reg"
if (Test-Path $pyReg)
{ reg import $pyReg
}
# Startup Shortcuts
Write-Host ":: Creating Startup Shortcuts..." -ForegroundColor Green
$startupDir = "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Startup"
$shortcuts = @{
"WezTerm" = "$env:USERPROFILE\scoop\apps\wezterm-nightly\current\wezterm-gui.exe"
"GlazeWM" = "$env:USERPROFILE\scoop\apps\glazewm\current\glazewm.exe"
"Microsoft Outlook" = "C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.EXE"
}
$wshell = New-Object -ComObject WScript.Shell
foreach ($name in $shortcuts.Keys)
{
$target = $shortcuts[$name]
if (Test-Path $target)
{
$lnk = $wshell.CreateShortcut("$startupDir\$name.lnk")
$lnk.TargetPath = $target
$lnk.Save()
}
}
# Build GlazeWM/Zebar
$zebarDir = "$env:USERPROFILE\.glzr\zebar\bar"
if (Test-Path $zebarDir)
{
Write-Host ":: Building Zebar..." -ForegroundColor Green
Push-Location $zebarDir
bun install
bun run build
Pop-Location
}
# BTOP Config
Write-Host ":: Configuring BTOP..." -ForegroundColor Green
$btopConfigDir = "$env:USERPROFILE\scoop\persist\btop"
$btopThemesDir = "$btopConfigDir\themes"
if (!(Test-Path $btopConfigDir))
{ New-Item -Path $btopConfigDir -ItemType Directory -Force | Out-Null
}
if (!(Test-Path $btopThemesDir))
{ New-Item -Path $btopThemesDir -ItemType Directory -Force | Out-Null
}
$srcBtop = "$env:USERPROFILE\.config\btop\btop.conf"
$srcTheme = "$env:USERPROFILE\.config\btop\themes\catppuccin_mocha.theme"
if (Test-Path $srcBtop)
{ Copy-Item $srcBtop "$btopConfigDir\btop.conf" -Force
}
if (Test-Path $srcTheme)
{ Copy-Item $srcTheme "$btopThemesDir\catppuccin_mocha.theme" -Force
}
# Zen Browser Config
Write-Host ":: Configuring Zen Browser..." -ForegroundColor Green
$zenConfig = "$env:USERPROFILE\.config\zen-styles"
$zenAppData = "$env:APPDATA\zen"
if (Test-Path $zenConfig)
{
if (Test-Path "$zenAppData\profiles.ini")
{
# Extract Path from profiles.ini (simple regex for the first Path= entry)
$profileRel = Select-String -Path "$zenAppData\profiles.ini" -Pattern "^Path=(.*)" | Select-Object -First 1
if ($profileRel)
{
# Convert forward slashes to backslashes for Windows path
$relPath = $profileRel.Matches.Groups[1].Value.Replace("/", "\")
$chromeDir = Join-Path $zenAppData "$relPath\chrome"
if (-not (Test-Path $chromeDir))
{ New-Item -ItemType Directory -Path $chromeDir -Force | Out-Null
}
Copy-Item "$zenConfig\*" "$chromeDir\" -Recurse -Force
Write-Host " Applied Zen Styles to $chromeDir" -ForegroundColor Gray
}
} else
{
Write-Warning " Zen Browser profiles.ini not found. Skipping style application."
}
}
# ------------------------------------------------------
# 9. ENVIRONMENT VARIABLES
# ------------------------------------------------------
Write-Host ":: Configuring Environment Variables..." -ForegroundColor Green
$ScoopGitBin = "$env:USERPROFILE\scoop\apps\git\current\bin"
$GitFileExe = "$env:USERPROFILE\scoop\apps\git\current\usr\bin\file.exe"
if (Test-Path $ScoopGitBin)
{
$UserPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($UserPath -notlike "*$ScoopGitBin*")
{
$NewPath = "$ScoopGitBin;$UserPath" # Prepend to beat shims
[Environment]::SetEnvironmentVariable("Path", $NewPath, "User")
Write-Host " Prepended Git Bin to PATH (Priority over shims)" -ForegroundColor Gray
}
if (Test-Path $GitFileExe)
{
[Environment]::SetEnvironmentVariable("YAZI_FILE_ONE", $GitFileExe, "User")
Write-Host " Set YAZI_FILE_ONE -> $GitFileExe" -ForegroundColor Gray
}
} else
{
Write-Warning " Could not find 'file.exe' in Scoop Git installation. Yazi might malfunction."
}
# 2. PATH CLEANUP
# Ensure the user's bin folder is in PATH (useful for scripts)
$UserBin = "$env:USERPROFILE\bin"
if (-not (Test-Path $UserBin))
{ New-Item -ItemType Directory -Path $UserBin -Force | Out-Null
}
$CurrentPath = [Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::User)
if ($CurrentPath -notlike "*$UserBin*")
{
[Environment]::SetEnvironmentVariable("Path", "$CurrentPath;$UserBin", [EnvironmentVariableTarget]::User)
Write-Host " Added ~\bin to PATH" -ForegroundColor Gray
}
# ------------------------------------------------------
# 10. POST-INSTALL CONFIGS
# ------------------------------------------------------
# WinUtil Tweaks
if (Test-Path ".\WinUtilTweaks.ps1")
{
Write-Host ":: Running WinUtil Tweaks..." -ForegroundColor Green
.\WinUtilTweaks.ps1 Invoke-All
}
# ------------------------------------------------------
# 11. FINISH
# ------------------------------------------------------
. $PROFILE
Write-Host ":: Setup Complete!" -ForegroundColor Green
if (gum confirm "Restart computer now?")
{
Restart-Computer
}
Write-Host "Configuration complete. Please restart the terminal."