-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.ps1
More file actions
269 lines (223 loc) · 10.2 KB
/
Copy pathbootstrap.ps1
File metadata and controls
269 lines (223 loc) · 10.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
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
Write-Host "[ERROR] This script must be run as Administrator (required for symlink creation)." -ForegroundColor Red
exit 1
}
$DotfilesDir = $PSScriptRoot
$CreateSymlink = Join-Path $DotfilesDir "windows\scripts\Create-Symlink.ps1"
function Write-Info { param([string]$Message) Write-Host "[INFO] $Message" -ForegroundColor Green }
function Write-Warn { param([string]$Message) Write-Host "[WARN] $Message" -ForegroundColor Yellow }
function Write-Step { param([string]$Message) Write-Host "[STEP] $Message" -ForegroundColor Blue }
$script:HasGum = $false
# ── Prompts (gum with Read-Host fallback) ─────────────────────
function Invoke-Confirm {
param([string]$Prompt)
if ($script:HasGum) {
gum confirm $Prompt
return $LASTEXITCODE -eq 0
} else {
$choice = Read-Host "$Prompt [Y/n]"
return (-not $choice -or $choice -match '^[Yy]')
}
}
function Invoke-ChooseMany {
param(
[string]$Header,
[string[]]$Items,
[string[]]$Selected = @()
)
if ($script:HasGum) {
$args_ = @("--no-limit", "--header", $Header)
if ($Selected.Count -gt 0) {
$args_ += @("--selected", ($Selected -join ","))
}
$result = $Items | gum choose @args_
if ($LASTEXITCODE -ne 0) { return @() }
return @($result)
} else {
Write-Host $Header
Write-Host "(space-separated, or 'all' for everything)"
foreach ($item in $Items) {
$marker = if ($Selected -contains $item) { "*" } else { " " }
Write-Host " [$marker] $item"
}
$input = Read-Host ">"
if ($input -eq "all") { return $Items }
if (-not $input) { return @() }
return @($input -split '\s+')
}
}
# ── Gum bootstrap ────────────────────────────────────────────
function Install-Gum {
if (Get-Command gum -ErrorAction SilentlyContinue) {
$script:HasGum = $true
return
}
Write-Step "gum not found - installing for interactive prompts..."
if (Get-Command winget -ErrorAction SilentlyContinue) {
winget install --id charmbracelet.gum --accept-source-agreements --accept-package-agreements 2>$null
# Refresh PATH
$env:Path = [Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [Environment]::GetEnvironmentVariable("Path", "User")
}
if (Get-Command gum -ErrorAction SilentlyContinue) {
$script:HasGum = $true
Write-Info "gum installed"
} else {
Write-Warn "Could not install gum, falling back to basic prompts"
}
}
# ── Tool installation ─────────────────────────────────────────
function Install-WingetPackage {
param(
[string]$PackageId,
[string]$Name
)
$installed = winget list --id $PackageId 2>$null | Select-String $PackageId
if ($installed) {
Write-Info "$Name is already installed"
return
}
Write-Info "Installing $Name..."
winget install --id $PackageId --accept-source-agreements --accept-package-agreements
if ($LASTEXITCODE -ne 0) {
Write-Warn "Failed to install $Name, skipping"
}
}
function Install-Tools {
Write-Step "Checking tools..."
if (-not (Get-Command winget -ErrorAction SilentlyContinue)) {
Write-Warn "winget not found. Install 'App Installer' from the Microsoft Store and re-run this script."
Write-Warn "https://aka.ms/getwinget"
return
}
$packages = @(
@{ Id = "Git.Git"; Name = "Git" },
@{ Id = "Neovim.Neovim"; Name = "Neovim" },
@{ Id = "AutoHotkey.AutoHotkey"; Name = "AutoHotkey" },
@{ Id = "glzr-io.glazewm"; Name = "GlazeWM" },
@{ Id = "glzr-io.zebar"; Name = "Zebar" },
@{ Id = "Schniz.fnm"; Name = "fnm" },
@{ Id = "junegunn.fzf"; Name = "fzf" },
@{ Id = "Starship.Starship"; Name = "Starship" },
@{ Id = "eza-community.eza"; Name = "eza" },
@{ Id = "ajeetdsouza.zoxide"; Name = "zoxide" }
)
# Find missing tools
$missing = @()
foreach ($pkg in $packages) {
$installed = winget list --id $pkg.Id 2>$null | Select-String $pkg.Id
if (-not $installed) {
$missing += $pkg
}
}
if ($missing.Count -eq 0) {
Write-Info "All tools already installed"
return
}
$missingNames = $missing | ForEach-Object { $_.Name }
$selected = Invoke-ChooseMany -Header "Select tools to install:" -Items $missingNames -Selected $missingNames
foreach ($name in $selected) {
$pkg = $missing | Where-Object { $_.Name -eq $name }
if ($pkg) {
Install-WingetPackage -PackageId $pkg.Id -Name $pkg.Name
}
}
# Refresh PATH so newly installed tools are available in this session
$env:Path = [Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [Environment]::GetEnvironmentVariable("Path", "User")
Write-Info "Refreshed PATH"
}
# ── Submodules ────────────────────────────────────────────────
function Initialize-Submodules {
Write-Step "Initializing git submodules..."
Push-Location $DotfilesDir
git submodule update --init --recursive
Pop-Location
Write-Info "Submodules initialized"
}
# ── Node.js ───────────────────────────────────────────────────
function Install-NodeLTS {
if (-not (Get-Command fnm -ErrorAction SilentlyContinue)) {
Write-Warn "fnm not found, skipping Node.js install"
return
}
Write-Step "Installing Node.js LTS via fnm..."
try {
fnm install --lts
fnm use lts-latest
fnm env --use-on-cd | Out-String | Invoke-Expression
Write-Info "Node.js LTS installed via fnm"
} catch {
Write-Warn "Failed to install Node.js via fnm: $_"
}
}
# ── Zebar ─────────────────────────────────────────────────────
function Build-ZebarWidget {
$zebarDir = Join-Path $DotfilesDir "glzr\.glzr\zebar\starter"
if (-not (Test-Path $zebarDir)) {
Write-Warn "Zebar starter directory not found at $zebarDir, skipping build"
return
}
Write-Step "Building Zebar widget..."
Push-Location $zebarDir
try {
npm install
npm run build
Write-Info "Zebar widget built"
} catch {
Write-Warn "Failed to build Zebar widget: $_"
} finally {
Pop-Location
}
}
# ── Symlinks ──────────────────────────────────────────────────
function New-Symlinks {
Write-Step "Creating symlinks..."
$symlinks = @(
@{ Name = "GlazeWM + Zebar"; Target = "glzr\.glzr"; Path = (Join-Path $HOME ".glzr") },
@{ Name = "AutoHotkey"; Target = "autohotkey\hotkey.ahk"; Path = (Join-Path $env:APPDATA "Microsoft\Windows\Start Menu\Programs\Startup\hotkey.ahk") },
@{ Name = "Neovim"; Target = "nvim\.config\nvim"; Path = (Join-Path $env:LOCALAPPDATA "nvim") },
@{ Name = "Git config"; Target = "git\.gitconfig"; Path = (Join-Path $HOME ".gitconfig") },
@{ Name = "Git ignore"; Target = "git\.gitignore"; Path = (Join-Path $HOME ".gitignore") },
@{ Name = "Windows Terminal"; Target = "wt\settings.json"; Path = (Join-Path $env:LOCALAPPDATA "Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json") },
@{ Name = "Scripts"; Target = "windows\scripts"; Path = (Join-Path $HOME "Documents\scripts") },
@{ Name = "PowerShell"; Target = "windows\profile\Microsoft.PowerShell_profile.ps1"; Path = (Join-Path $HOME "Documents\PowerShell\Microsoft.PowerShell_profile.ps1") }
)
$names = $symlinks | ForEach-Object { $_.Name }
$selected = Invoke-ChooseMany -Header "Select symlinks to create:" -Items $names -Selected $names
foreach ($name in $selected) {
$link = $symlinks | Where-Object { $_.Name -eq $name }
if ($link) {
$target = Join-Path $DotfilesDir $link.Target
& $CreateSymlink $target $link.Path
}
}
}
# ── Git config ────────────────────────────────────────────────
function Set-GitLocalConfig {
$gitconfigLocal = Join-Path $HOME ".gitconfig.local"
if ((Test-Path (Join-Path $HOME ".gitconfig")) -and (-not (Test-Path $gitconfigLocal))) {
Write-Warn "~/.gitconfig.local not found"
Write-Info "Copy the example and fill in your details:"
Write-Info " cp $DotfilesDir\git\.gitconfig.local.example ~\.gitconfig.local"
}
}
# ── Main ──────────────────────────────────────────────────────
function Main {
Write-Host ""
Write-Host ([char]0x2554 + ([string][char]0x2550) * 39 + [char]0x2557)
Write-Host ([char]0x2551 + " Dotfiles Bootstrap (Windows) " + [char]0x2551)
Write-Host ([char]0x255A + ([string][char]0x2550) * 39 + [char]0x255D)
Write-Host ""
Install-Gum
Install-Tools
Install-NodeLTS
Initialize-Submodules
Build-ZebarWidget
New-Symlinks
Set-GitLocalConfig
Write-Host ""
Write-Info "Bootstrap complete!"
}
Main