-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.ps1
More file actions
134 lines (112 loc) · 5.01 KB
/
Copy pathbootstrap.ps1
File metadata and controls
134 lines (112 loc) · 5.01 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
<#
.SYNOPSIS
Bootstrap WezTerm + Oh My Posh config from dotfiles-koo onto Windows.
.DESCRIPTION
- Installs WezTerm and Oh My Posh via winget if available
- Copies wezterm config to $env:USERPROFILE\.config\wezterm
- Copies oh-my-posh theme to $env:USERPROFILE\.config\ohmyposh
- Appends oh-my-posh init to PowerShell profile if not already present
.USAGE
Run from repo root:
.\bootstrap.ps1
Dry run (preview only, no changes):
.\bootstrap.ps1 -DryRun
.NOTES
Requires PowerShell 7 (pwsh). Run as regular user — no elevation needed.
#>
[CmdletBinding()]
param (
[switch]$DryRun
)
$ErrorActionPreference = 'Stop'
$repoRoot = $PSScriptRoot
function Write-Step($msg) { Write-Host "`n>> $msg" -ForegroundColor Cyan }
function Write-Ok($msg) { Write-Host " OK $msg" -ForegroundColor Green }
function Write-Skip($msg) { Write-Host " -- $msg" -ForegroundColor DarkGray }
function Write-Warn($msg) { Write-Warning " $msg" }
function Safe-Copy($src, $dst) {
if (-not (Test-Path $src)) {
Write-Warn "Source not found, skipping: $src"
return
}
if ($DryRun) {
Write-Skip "[DryRun] Would copy $src -> $dst"
return
}
New-Item -ItemType Directory -Force -Path (Split-Path $dst) | Out-Null
Copy-Item -Path $src -Destination $dst -Recurse -Force
Write-Ok "Copied $src -> $dst"
}
# ── 1. Install via winget ─────────────────────────────────────────────────────
Write-Step "Installing tools via winget"
if (Get-Command winget -ErrorAction SilentlyContinue) {
foreach ($pkg in @(
@{ id = 'WezTerm.WezTerm'; label = 'WezTerm' },
@{ id = 'JanDeDobbeleer.OhMyPosh'; label = 'Oh My Posh' }
)) {
if ($DryRun) {
Write-Skip "[DryRun] Would install $($pkg.label)"
} else {
try {
winget install --id $pkg.id -e --silent `
--accept-source-agreements --accept-package-agreements
Write-Ok "$($pkg.label) installed"
} catch {
Write-Skip "$($pkg.label) already installed or install skipped"
}
}
}
} else {
Write-Warn "winget not found. Install WezTerm and Oh My Posh manually:"
Write-Warn " https://wezfurlong.org/wezterm/install/windows.html"
Write-Warn " https://ohmyposh.dev/docs/installation/windows"
}
# ── 2. Copy WezTerm config ────────────────────────────────────────────────────
Write-Step "Copying WezTerm config"
$weztermSrc = Join-Path $repoRoot 'wezterm'
$weztermDst = Join-Path $env:USERPROFILE '.config\wezterm'
if (Test-Path (Join-Path $weztermDst 'wezterm.lua')) {
Write-Warn "Existing WezTerm config found at $weztermDst"
$confirm = if ($DryRun) { 'n' } else { Read-Host " Overwrite? [y/N]" }
if ($confirm -ne 'y') {
Write-Skip "Skipping WezTerm config copy"
} else {
Safe-Copy $weztermSrc $weztermDst
}
} else {
Safe-Copy $weztermSrc $weztermDst
}
# ── 3. Copy Oh My Posh theme ──────────────────────────────────────────────────
Write-Step "Copying Oh My Posh theme"
$ompSrc = Join-Path $repoRoot 'ohmyposh\.poshconfig.json'
$ompDst = Join-Path $env:USERPROFILE '.config\ohmyposh\.poshconfig.json'
Safe-Copy $ompSrc $ompDst
# ── 4. Wire up PowerShell profile ────────────────────────────────────────────
Write-Step "Updating PowerShell profile"
$profilePath = $PROFILE.CurrentUserAllHosts
$initLine = "oh-my-posh init pwsh --config `"$ompDst`" | Invoke-Expression"
if (-not (Test-Path $profilePath)) {
if (-not $DryRun) {
New-Item -ItemType File -Force -Path $profilePath | Out-Null
}
}
$profileContent = if (Test-Path $profilePath) { Get-Content $profilePath -Raw } else { '' }
if ($profileContent -match [regex]::Escape('oh-my-posh init pwsh')) {
Write-Skip "Profile already contains oh-my-posh init — not modified"
} elseif ($DryRun) {
Write-Skip "[DryRun] Would append oh-my-posh init to $profilePath"
} else {
Add-Content -Path $profilePath -Value "`n# Oh My Posh — dotfiles-koo`n$initLine`n"
Write-Ok "Appended oh-my-posh init to $profilePath"
}
# ── 5. Summary ────────────────────────────────────────────────────────────────
Write-Host ""
Write-Host "Bootstrap complete." -ForegroundColor Green
if ($DryRun) {
Write-Host "(DryRun — no files were modified)" -ForegroundColor Yellow
} else {
Write-Host "Next steps:" -ForegroundColor Cyan
Write-Host " 1. Fully close and reopen WezTerm (not just config reload)"
Write-Host " 2. Open a new pwsh session to pick up profile changes"
Write-Host " 3. Verify: wezterm --version && Get-Command oh-my-posh"
}