-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindows-install.ps1
More file actions
433 lines (354 loc) · 14.7 KB
/
Copy pathwindows-install.ps1
File metadata and controls
433 lines (354 loc) · 14.7 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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
#!/usr/bin/env pwsh
# Windows Dotfiles Installation Script
# This script sets up your development environment on Windows
# Run this in PowerShell 5.1+ or PowerShell 7+
#
# Usage: .\windows-install.ps1
#Requires -Version 5.1
param(
[switch]$SkipPackages,
[switch]$SkipDotfiles,
[switch]$SkipShell,
[switch]$SkipVim,
[switch]$Force
)
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"
# ============================================
# Helper Functions
# ============================================
function Write-Step {
param([string]$Message)
Write-Host "`n==> $Message" -ForegroundColor Cyan
}
function Write-Success {
param([string]$Message)
Write-Host "✓ $Message" -ForegroundColor Green
}
function Write-Warning {
param([string]$Message)
Write-Host "⚠ $Message" -ForegroundColor Yellow
}
function Write-Failure {
param([string]$Message)
Write-Host "✗ $Message" -ForegroundColor Red
}
function Test-Administrator {
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
function Install-ScoopIfNeeded {
if (Get-Command scoop -ErrorAction SilentlyContinue) {
Write-Success "Scoop is already installed"
return
}
Write-Step "Installing Scoop package manager"
# Set execution policy for current user
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
# Install Scoop
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression
if (Get-Command scoop -ErrorAction SilentlyContinue) {
Write-Success "Scoop installed successfully"
} else {
Write-Failure "Failed to install Scoop"
exit 1
}
}
function Install-GitIfNeeded {
if (Get-Command git -ErrorAction SilentlyContinue) {
Write-Success "Git is already installed"
return
}
Write-Step "Installing Git via Scoop"
scoop install git
if (Get-Command git -ErrorAction SilentlyContinue) {
Write-Success "Git installed successfully"
} else {
Write-Failure "Failed to install Git"
exit 1
}
}
# ============================================
# Main Installation Steps
# ============================================
Write-Host @"
╔══════════════════════════════════════════════════╗
║ Windows Dotfiles Installation ║
║ Setting up your development environment ║
╚══════════════════════════════════════════════════╝
"@ -ForegroundColor Cyan
# Check PowerShell version
$psVersion = $PSVersionTable.PSVersion
Write-Host "PowerShell Version: $psVersion"
if ($psVersion.Major -lt 5) {
Write-Failure "PowerShell 5.1 or higher is required"
Write-Host "Please upgrade PowerShell: https://aka.ms/powershell"
exit 1
}
# Get dotfiles directory (where this script is located)
$dotfilesDir = Split-Path -Parent $MyInvocation.MyCommand.Path
Write-Host "Dotfiles directory: $dotfilesDir`n"
# ============================================
# Load the package manifest
# ============================================
# packages.yml is the single source of truth for what gets installed,
# shared with the Ansible roles on Linux/macOS.
if (-not (Get-Module -ListAvailable -Name powershell-yaml)) {
Write-Step "Installing powershell-yaml module (needed to read packages.yml)"
Install-Module -Name powershell-yaml -Scope CurrentUser -Force -SkipPublisherCheck
}
Import-Module powershell-yaml
$manifest = ConvertFrom-Yaml (Get-Content "$dotfilesDir\packages.yml" -Raw)
$scoopPackages = @($manifest.Values | Where-Object { $_.scoop } | ForEach-Object { $_.scoop })
$pipPackages = @($manifest.Values | Where-Object { $_.pip } | ForEach-Object { $_.pip })
$npmPackages = @($manifest.Values | Where-Object { $_.npm } | ForEach-Object { $_.npm })
# ============================================
# Step 1: Install Scoop and Git
# ============================================
Write-Step "Installing prerequisites"
Install-ScoopIfNeeded
Install-GitIfNeeded
# ============================================
# Step 2: Install Packages
# ============================================
if (-not $SkipPackages) {
Write-Step "Installing packages via Scoop"
# Add Scoop buckets
Write-Host "Adding Scoop buckets..."
$buckets = @('extras', 'nerd-fonts', 'versions')
foreach ($bucket in $buckets) {
Write-Host " Adding bucket: $bucket"
scoop bucket add $bucket 2>$null
}
Write-Success "Buckets added"
# Core packages (from packages.yml)
Write-Host "`nInstalling core packages..."
foreach ($package in $scoopPackages) {
if (scoop list $package 2>$null) {
Write-Host " ✓ $package (already installed)" -ForegroundColor Gray
} else {
Write-Host " Installing $package..." -NoNewline
$result = scoop install $package 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Host " ✓" -ForegroundColor Green
} else {
Write-Host " ⚠" -ForegroundColor Yellow
}
}
}
# Install Nerd Fonts
Write-Host "`nInstalling Nerd Fonts..."
$fonts = @('FiraCode-NF', 'CascadiaCode-NF')
foreach ($font in $fonts) {
if (scoop list $font 2>$null) {
Write-Host " ✓ $font (already installed)" -ForegroundColor Gray
} else {
Write-Host " Installing $font..." -NoNewline
scoop install $font 2>&1 | Out-Null
if ($LASTEXITCODE -eq 0) {
Write-Host " ✓" -ForegroundColor Green
} else {
Write-Host " ⚠" -ForegroundColor Yellow
}
}
}
# Install Python packages (from packages.yml)
Write-Host "`nInstalling Python packages..."
foreach ($pip in $pipPackages) {
Write-Host " Installing $pip..." -NoNewline
python -m pip install $pip --quiet 2>&1 | Out-Null
if ($LASTEXITCODE -eq 0) {
Write-Host " ✓" -ForegroundColor Green
} else {
Write-Host " ⚠" -ForegroundColor Yellow
}
}
Write-Success "Package installation complete"
}
# ============================================
# Step 3: Install PowerShell Modules
# ============================================
if (-not $SkipShell) {
Write-Step "Installing PowerShell modules"
$modules = @('PSReadLine', 'PSFzf', 'posh-git', 'Terminal-Icons')
foreach ($module in $modules) {
if (Get-Module -ListAvailable -Name $module) {
Write-Host " ✓ $module (already installed)" -ForegroundColor Gray
} else {
Write-Host " Installing $module..." -NoNewline
Install-Module -Name $module -Scope CurrentUser -Force -SkipPublisherCheck -ErrorAction SilentlyContinue
if (Get-Module -ListAvailable -Name $module) {
Write-Host " ✓" -ForegroundColor Green
} else {
Write-Host " ⚠" -ForegroundColor Yellow
}
}
}
Write-Success "PowerShell modules installed"
}
# ============================================
# Step 4: Setup Dotfiles (Symlinks)
# ============================================
if (-not $SkipDotfiles) {
Write-Step "Setting up dotfiles"
# Create necessary directories
$configDir = "$env:LOCALAPPDATA"
$docsDir = "$env:USERPROFILE\Documents\PowerShell"
New-Item -ItemType Directory -Path $docsDir -Force | Out-Null
# Link Git configuration
Write-Host "`nLinking Git configuration..."
$gitFiles = @('gitconfig', 'gitignore')
foreach ($file in $gitFiles) {
$source = "$dotfilesDir\roles\dotfiles\files\$file"
$target = "$env:USERPROFILE\.$file"
if (Test-Path $source) {
if (Test-Path $target) {
Remove-Item $target -Force -ErrorAction SilentlyContinue
}
try {
New-Item -ItemType SymbolicLink -Path $target -Target $source -Force -ErrorAction Stop | Out-Null
Write-Host " ✓ Linked .$file" -ForegroundColor Green
} catch {
Write-Host " ⚠ Could not link .$file (try running as Administrator)" -ForegroundColor Yellow
Copy-Item $source $target -Force
Write-Host " Copied instead of symlinked" -ForegroundColor Yellow
}
}
}
# Link PowerShell profile
Write-Host "`nLinking PowerShell profile..."
$profileSource = "$dotfilesDir\windows\Microsoft.PowerShell_profile.ps1"
$profileTarget = $PROFILE
if (Test-Path $profileSource) {
$profileDir = Split-Path $profileTarget -Parent
New-Item -ItemType Directory -Path $profileDir -Force | Out-Null
if (Test-Path $profileTarget) {
Remove-Item $profileTarget -Force -ErrorAction SilentlyContinue
}
try {
New-Item -ItemType SymbolicLink -Path $profileTarget -Target $profileSource -Force -ErrorAction Stop | Out-Null
Write-Host " ✓ Linked PowerShell profile" -ForegroundColor Green
} catch {
Copy-Item $profileSource $profileTarget -Force
Write-Host " ⚠ Copied PowerShell profile (try running as Administrator for symlink)" -ForegroundColor Yellow
}
}
# Link PowerShell modules
Write-Host "`nLinking PowerShell modules..."
$modulesSource = "$dotfilesDir\windows\powershell"
$modulesTarget = "$docsDir\powershell"
if (Test-Path $modulesSource) {
try {
New-Item -ItemType SymbolicLink -Path $modulesTarget -Target $modulesSource -Force -ErrorAction Stop | Out-Null
Write-Host " ✓ Linked PowerShell modules" -ForegroundColor Green
} catch {
Copy-Item $modulesSource $modulesTarget -Recurse -Force
Write-Host " ⚠ Copied PowerShell modules" -ForegroundColor Yellow
}
}
# Link Starship config
Write-Host "`nLinking Starship configuration..."
$starshipSource = "$dotfilesDir\windows\starship.toml"
$starshipTarget = "$env:USERPROFILE\.config\starship.toml"
if (Test-Path $starshipSource) {
$starshipDir = Split-Path $starshipTarget -Parent
New-Item -ItemType Directory -Path $starshipDir -Force | Out-Null
try {
New-Item -ItemType SymbolicLink -Path $starshipTarget -Target $starshipSource -Force -ErrorAction Stop | Out-Null
Write-Host " ✓ Linked Starship config" -ForegroundColor Green
} catch {
Copy-Item $starshipSource $starshipTarget -Force
Write-Host " ⚠ Copied Starship config" -ForegroundColor Yellow
}
}
Write-Success "Dotfiles setup complete"
}
# ============================================
# Step 5: Setup Neovim
# ============================================
if (-not $SkipVim) {
Write-Step "Setting up Neovim"
# Create local directories
$localBin = "$env:USERPROFILE\.local\bin"
New-Item -ItemType Directory -Path $localBin -Force | Out-Null
# Link Neovim config
$nvimSource = "$dotfilesDir\lazy"
$nvimTarget = "$env:LOCALAPPDATA\nvim"
if (Test-Path $nvimSource) {
if (Test-Path $nvimTarget) {
Write-Host " Removing existing Neovim config..."
Remove-Item $nvimTarget -Recurse -Force -ErrorAction SilentlyContinue
}
try {
New-Item -ItemType SymbolicLink -Path $nvimTarget -Target $nvimSource -Force -ErrorAction Stop | Out-Null
Write-Host " ✓ Linked Neovim config" -ForegroundColor Green
} catch {
Copy-Item $nvimSource $nvimTarget -Recurse -Force
Write-Host " ⚠ Copied Neovim config (try running as Administrator for symlink)" -ForegroundColor Yellow
}
}
# Verify Neovim installation
if (Get-Command nvim -ErrorAction SilentlyContinue) {
$nvimVersion = (nvim --version | Select-Object -First 1).Trim()
Write-Success "Neovim setup complete: $nvimVersion"
} else {
Write-Warning "Neovim not found in PATH. You may need to restart your terminal."
}
}
# ============================================
# Step 6: Initialize Tools
# ============================================
if (-not $SkipShell) {
Write-Step "Initializing development tools"
# Initialize fnm and install Node.js LTS
if (Get-Command fnm -ErrorAction SilentlyContinue) {
Write-Host " Installing Node.js LTS via fnm..." -NoNewline
fnm install --lts 2>&1 | Out-Null
fnm default lts-latest 2>&1 | Out-Null
Write-Host " ✓" -ForegroundColor Green
# Install global npm packages (from packages.yml)
fnm env --use-on-cd | Out-String | Invoke-Expression
if (Get-Command npm -ErrorAction SilentlyContinue) {
foreach ($npmPackage in $npmPackages) {
Write-Host " Installing npm package $npmPackage..." -NoNewline
npm install -g $npmPackage 2>&1 | Out-Null
if ($LASTEXITCODE -eq 0) {
Write-Host " ✓" -ForegroundColor Green
} else {
Write-Host " ⚠" -ForegroundColor Yellow
}
}
}
}
# Initialize Rust
if (Get-Command rustup -ErrorAction SilentlyContinue) {
Write-Host " Updating Rust toolchain..." -NoNewline
rustup default stable 2>&1 | Out-Null
Write-Host " ✓" -ForegroundColor Green
}
Write-Success "Development tools initialized"
}
# ============================================
# Completion Message
# ============================================
Write-Host @"
╔══════════════════════════════════════════════════╗
║ Installation Complete! ║
╚══════════════════════════════════════════════════╝
Next steps:
1. RESTART YOUR TERMINAL (or run: . `$PROFILE)
2. Run 'nvim' to start Neovim (plugins will auto-install)
3. Customize your setup:
- Edit PowerShell profile: `$PROFILE
- Edit Neovim config: $env:LOCALAPPDATA\nvim
- Edit Starship prompt: $env:USERPROFILE\.config\starship.toml
Useful commands:
nvim Open Neovim
z <dir> Jump to directory (zoxide)
fnm list List installed Node versions
scoop update * Update all packages
gh repo clone Clone GitHub repository
"@ -ForegroundColor Green
Write-Host "Press any key to exit..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")