-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
180 lines (159 loc) · 7.19 KB
/
Copy pathinstall.ps1
File metadata and controls
180 lines (159 loc) · 7.19 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
# Idempotent installer for the dev-workspace toolbox. Re-running is safe.
#
# git clone https://github.com/edglz/dev-workspace.git
# cd dev-workspace
# .\install.ps1
#
# Flags: -SkipScoop -SkipPip -SkipNpm -SkipProfile -SkipSettings
[CmdletBinding()]
param(
[switch]$SkipScoop,
[switch]$SkipPip,
[switch]$SkipNpm,
[switch]$SkipProfile,
[switch]$SkipSettings
)
$ErrorActionPreference = 'Stop'
$root = Split-Path -Parent $MyInvocation.MyCommand.Path
function Write-Step { param([string]$M) Write-Host "==> $M" -ForegroundColor Cyan }
function Write-Skip { param([string]$M) Write-Host " skip: $M" -ForegroundColor DarkGray }
function Write-Done { param([string]$M) Write-Host " ok: $M" -ForegroundColor Green }
# Refresh the current session's PATH from the user/machine registry values.
# Required after scoop/pip/npm modify user PATH so subsequent steps can find
# the freshly installed binaries without opening a new shell.
function Update-SessionPath {
$env:Path = [Environment]::GetEnvironmentVariable('Path','Machine') + ';' +
[Environment]::GetEnvironmentVariable('Path','User')
}
function Add-UserPath {
param([Parameter(Mandatory)][string]$Dir)
$cur = [Environment]::GetEnvironmentVariable('Path','User')
if (($cur -split ';') -contains $Dir) { return }
[Environment]::SetEnvironmentVariable('Path', "$cur;$Dir", 'User')
Update-SessionPath
}
function Test-ScoopBucket {
param([string]$Name)
(scoop bucket list 2>&1 | Out-String) -match "(?m)^\s*$Name\s"
}
function Test-ScoopPackage {
param([string]$Name)
$entry = scoop list $Name 6>$null | Where-Object Name -eq $Name
# A half-completed install still shows in `scoop list` but carries an
# "Install failed" note. Treat that as not-installed so it gets retried.
[bool]$entry -and $entry.Info -notmatch 'Install failed'
}
# Remove any package left in a failed/partial state. Scoop refuses to cleanly
# reinstall over leftover files, so a single interrupted install otherwise
# blocks every future run. Clearing the app + persist dirs lets the retry work.
function Clear-FailedScoopPackage {
param([string]$Name)
$entry = scoop list $Name 6>$null | Where-Object Name -eq $Name
if ($entry -and $entry.Info -match 'Install failed') {
scoop uninstall $Name 2>&1 | Out-Null
Remove-Item "$env:USERPROFILE\scoop\apps\$Name" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item "$env:USERPROFILE\scoop\persist\$Name" -Recurse -Force -ErrorAction SilentlyContinue
Write-Done "cleaned failed install: $Name"
}
}
# 1. Scoop bootstrap, buckets, packages
if (-not $SkipScoop) {
Write-Step 'Scoop'
if (-not (Get-Command scoop -ErrorAction SilentlyContinue)) {
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression
Update-SessionPath
}
Write-Done 'scoop available'
foreach ($b in 'extras','java') {
if (Test-ScoopBucket $b) { Write-Skip "bucket $b" } else {
scoop bucket add $b | Out-Null
Write-Done "bucket $b added"
}
}
$packages = @(
'eza','bat','fd','ripgrep','zoxide','sd','dust','duf','delta','difftastic',
'xh','dog','btop','procs','hyperfine','tealdeer','jaq','dasel','yq',
'fzf','lazygit','just','watchexec','gping','trippy','tokei',
'nodejs','bun','pnpm','deno','python','go','temurin21-jdk','gradle','maven','mise',
'gh','atac','grpcurl','mongosh','supabase','ngrok','cloudflared',
'kubectl','k9s','kubectx','kubens','helm','stern','dive','minikube','kind',
'terraform','pulumi','flutter','glow','rclone','oh-my-posh'
)
Write-Step "Scoop packages ($($packages.Count))"
foreach ($p in $packages) { Clear-FailedScoopPackage $p }
$missing = $packages | Where-Object { -not (Test-ScoopPackage $_) }
# Install one at a time so a single bad package can't abort the batch and
# leave the rest uninstalled. Each failure is reported but non-fatal.
foreach ($p in $missing) {
try { scoop install $p } catch { Write-Host " warn: $p failed - $_" -ForegroundColor Yellow }
}
if (-not $missing) { Write-Skip 'all already installed' }
foreach ($n in 'temurin21-jdk','maven','flutter') {
if (Test-ScoopPackage $n) { scoop reset $n | Out-Null }
}
Update-SessionPath
Write-Done 'scoop done'
}
# 2. pip user installs
if (-not $SkipPip) {
Write-Step 'pip user installs'
if (-not (Get-Command python -ErrorAction SilentlyContinue)) {
Write-Skip 'python not on PATH'
} else {
python -m pip install --user --upgrade httpie posting pgcli | Out-Null
$userBase = (python -c "import site; print(site.USER_BASE)" 2>&1) -split "`n" | Select-Object -First 1
Add-UserPath (Join-Path $userBase.Trim() 'Scripts')
Write-Done 'httpie, posting, pgcli'
}
}
# 3. npm globals
if (-not $SkipNpm) {
Write-Step 'npm globals'
if (-not (Get-Command npm -ErrorAction SilentlyContinue)) {
Write-Skip 'npm not on PATH'
} else {
npm install -g wrangler @expo/cli 2>&1 | Out-Null
Write-Done 'wrangler, @expo/cli'
}
}
# 4. Profile
if (-not $SkipProfile) {
Write-Step 'PowerShell profile'
$allHosts = "$env:USERPROFILE\Documents\PowerShell\profile.ps1"
New-Item -ItemType Directory -Path (Split-Path $allHosts) -Force | Out-Null
Copy-Item "$root\profile.ps1" $allHosts -Force
Write-Done $allHosts
$ompTheme = Join-Path (Split-Path $allHosts) 'workspace.omp.json'
Copy-Item "$root\workspace.omp.json" $ompTheme -Force
Write-Done $ompTheme
$winPs = "$env:USERPROFILE\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1"
New-Item -ItemType Directory -Path (Split-Path $winPs) -Force | Out-Null
Copy-Item "$root\windowsPowerShell-stub.ps1" $winPs -Force
Write-Done $winPs
}
# 5. Claude settings - merge into existing or create fresh
if (-not $SkipSettings) {
Write-Step 'Claude settings.json'
$claudeDir = "$env:USERPROFILE\.claude"
New-Item -ItemType Directory -Path $claudeDir -Force | Out-Null
$target = "$claudeDir\settings.json"
$template = Get-Content "$root\settings.template.json" -Raw | ConvertFrom-Json
if (Test-Path $target) {
Copy-Item $target "$target.bak" -Force
Write-Done "backup -> $target.bak"
$current = Get-Content $target -Raw | ConvertFrom-Json
# Add-Member -Force adds or overwrites; plain assignment throws on a
# missing property under Windows PowerShell 5.1.
$current | Add-Member -NotePropertyName attribution -NotePropertyValue $template.attribution -Force
$current | Add-Member -NotePropertyName permissions -NotePropertyValue $template.permissions -Force
if ($template.hooks) { $current | Add-Member -NotePropertyName hooks -NotePropertyValue $template.hooks -Force }
$current | ConvertTo-Json -Depth 10 | Set-Content $target -Encoding UTF8
Write-Done "merged into $target"
} else {
Copy-Item "$root\settings.template.json" $target -Force
Write-Done "created $target"
}
}
Write-Host ''
Write-Host 'Done. Open a new PowerShell session and run: ws' -ForegroundColor Green