-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ps1
More file actions
189 lines (157 loc) · 6.2 KB
/
Copy pathsetup.ps1
File metadata and controls
189 lines (157 loc) · 6.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
[CmdletBinding(SupportsShouldProcess)]
param(
[switch]$SkipRecommendedPackages,
[switch]$SkipClaudeCode,
[switch]$SkipProfileBootstrap
)
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
$requiredPackages = @(
@{ Id = 'CoreyButler.NVMforWindows'; Description = 'Node version management' }
@{ Id = 'Ditto.Ditto'; Description = 'Clipboard manager' }
@{ Id = 'Git.Git'; Description = 'Git CLI' }
@{ Id = 'GitHub.cli'; Description = 'GitHub CLI' }
@{ Id = 'GitHub.Copilot'; Description = 'GitHub Copilot CLI tooling' }
@{ Id = 'GitHub.GitHubDesktop'; Description = 'GitHub Desktop' }
@{ Id = 'Google.Chrome'; Description = 'Primary browser' }
@{ Id = 'Microsoft.PowerShell'; Description = 'PowerShell 7' }
@{ Id = 'Microsoft.PowerToys'; Description = 'Windows productivity tools' }
@{ Id = 'Microsoft.VisualStudioCode.Insiders'; Description = 'VS Code Insiders' }
@{ Id = 'Microsoft.VisualStudio.Community.Insiders'; Description = 'Visual Studio Community Insiders' }
@{ Id = 'Anthropic.Claude'; Description = 'Claude desktop app' }
@{ Id = 'Microsoft.Teams'; Description = 'Teams client' }
@{ Id = 'Microsoft.WindowsTerminal'; Description = 'Windows Terminal' }
@{ Id = 'Microsoft.WSL'; Description = 'Windows Subsystem for Linux' }
@{ Id = 'Canonical.Ubuntu'; Description = 'Ubuntu for WSL' }
)
$recommendedPackages = @(
@{ Id = '7zip.7zip'; Description = 'Archive tooling' }
@{ Id = 'BurntSushi.ripgrep.MSVC'; Description = 'Fast code search' }
@{ Id = 'sharkdp.fd'; Description = 'Fast file finder' }
@{ Id = 'jqlang.jq'; Description = 'JSON CLI tooling' }
@{ Id = 'JesseDuffield.lazygit'; Description = 'TUI for Git' }
@{ Id = 'Docker.DockerDesktop'; Description = 'Local containers' }
@{ Id = 'Python.Python.3.13'; Description = 'Python runtime' }
@{ Id = 'Microsoft.AzureCLI'; Description = 'Azure CLI' }
@{ Id = 'Bruno.Bruno'; Description = 'API client' }
@{ Id = 'Neovim.Neovim'; Description = 'Terminal editor' }
)
function Test-CommandAvailable {
param(
[Parameter(Mandatory)]
[string]$Name
)
return [bool](Get-Command -Name $Name -ErrorAction SilentlyContinue)
}
function Sync-PathEnvironment {
$machinePath = [Environment]::GetEnvironmentVariable('Path', 'Machine')
$userPath = [Environment]::GetEnvironmentVariable('Path', 'User')
$combinedPaths = @($machinePath, $userPath) -join ';'
$env:Path = (
$combinedPaths -split ';' |
Where-Object { -not [string]::IsNullOrWhiteSpace($_) } |
Select-Object -Unique
) -join ';'
foreach ($name in 'NVM_HOME', 'NVM_SYMLINK') {
$userValue = [Environment]::GetEnvironmentVariable($name, 'User')
$machineValue = [Environment]::GetEnvironmentVariable($name, 'Machine')
$value = if ($userValue) { $userValue } else { $machineValue }
if ($value) {
Set-Item -Path "Env:$name" -Value $value
}
}
}
function Test-WingetPackageInstalled {
param(
[Parameter(Mandatory)]
[string]$Id
)
$output = & winget list --id $Id --exact --accept-source-agreements 2>$null | Out-String
return $LASTEXITCODE -eq 0 -and $output -match [regex]::Escape($Id)
}
function Install-WingetPackage {
param(
[Parameter(Mandatory)]
[hashtable]$Package
)
if (Test-WingetPackageInstalled -Id $Package.Id) {
Write-Host "Skipping $($Package.Id); already installed." -ForegroundColor DarkGray
return
}
if ($PSCmdlet.ShouldProcess($Package.Id, 'Install package with winget')) {
Write-Host "Installing $($Package.Id) ($($Package.Description))..." -ForegroundColor Yellow
& winget install --id $Package.Id --exact --source winget --accept-package-agreements --accept-source-agreements --silent
if ($LASTEXITCODE -ne 0) {
throw "winget install failed for $($Package.Id)."
}
}
}
function Install-LatestNode {
if (-not (Test-CommandAvailable -Name 'nvm')) {
throw 'nvm is not available in the current session. Re-run this script in a new PowerShell window if the refresh step did not pick it up.'
}
if ($PSCmdlet.ShouldProcess('Node.js', 'Install latest version via nvm')) {
Write-Host 'Installing latest Node.js via nvm...' -ForegroundColor Yellow
& nvm install latest
if ($LASTEXITCODE -ne 0) {
throw 'nvm install latest failed.'
}
Write-Host 'Activating latest Node.js via nvm...' -ForegroundColor Yellow
& nvm use latest
if ($LASTEXITCODE -ne 0) {
throw 'nvm use latest failed.'
}
Sync-PathEnvironment
if (Test-CommandAvailable -Name 'node') {
$nodeVersion = (& node --version).Trim()
Write-Host "Active Node.js version: $nodeVersion" -ForegroundColor Green
} else {
Write-Warning 'Node.js was installed, but node is not yet visible in this session. Open a new PowerShell window if needed.'
}
}
}
function Install-ClaudeCode {
if (Test-CommandAvailable -Name 'claude') {
Write-Host 'Skipping Claude Code CLI; command is already available.' -ForegroundColor DarkGray
return
}
if ($PSCmdlet.ShouldProcess('Claude Code CLI', 'Install from official script')) {
Write-Host 'Installing Claude Code CLI...' -ForegroundColor Yellow
Invoke-RestMethod https://claude.ai/install.ps1 | Invoke-Expression
}
}
if (-not (Test-CommandAvailable -Name 'winget')) {
throw 'winget is required but was not found on PATH.'
}
Write-Host 'Installing required winget packages...' -ForegroundColor Cyan
foreach ($package in $requiredPackages) {
Install-WingetPackage -Package $package
}
if ($SkipRecommendedPackages) {
Write-Host 'Skipping recommended developer packages.' -ForegroundColor Cyan
Write-Host 'Recommended package set:' -ForegroundColor DarkGray
foreach ($package in $recommendedPackages) {
Write-Host " $($package.Id) - $($package.Description)" -ForegroundColor DarkGray
}
} else {
Write-Host 'Installing recommended developer packages...' -ForegroundColor Cyan
foreach ($package in $recommendedPackages) {
Install-WingetPackage -Package $package
}
}
Sync-PathEnvironment
Install-LatestNode
if (-not $SkipClaudeCode) {
Install-ClaudeCode
}
if (-not $SkipProfileBootstrap) {
$setupProfileScript = Join-Path $PSScriptRoot 'setup-profile.ps1'
if (Test-Path $setupProfileScript) {
if ($PSCmdlet.ShouldProcess($setupProfileScript, 'Bootstrap PowerShell profile')) {
& $setupProfileScript -WhatIf:$WhatIfPreference
}
} else {
Write-Warning "Could not find $setupProfileScript"
}
}
Write-Host 'Bootstrap complete.' -ForegroundColor Green