-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinstall.ps1
More file actions
257 lines (226 loc) · 8.96 KB
/
Copy pathinstall.ps1
File metadata and controls
257 lines (226 loc) · 8.96 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
#Requires -Version 5.1
<#
.SYNOPSIS
Installer for Claude Code Statusline (Windows)
.DESCRIPTION
Downloads the latest statusline binary and configures Claude Code.
.EXAMPLE
& ([scriptblock]::Create((irm https://raw.githubusercontent.com/glauberlima/claude-code-statusline/main/install.ps1)))
.EXAMPLE
.\install.ps1 -InstallDir C:\custom\path
#>
param(
[string]$InstallDir,
[string]$Version
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$GithubRepo = "glauberlima/claude-code-statusline"
$GithubApi = "https://api.github.com/repos/$GithubRepo/releases/latest"
$GithubDlBase = "https://github.com/$GithubRepo/releases/download"
$MaxRetries = 3
# ── Derived paths ──────────────────────────────────────────────────────────────
if ([string]::IsNullOrEmpty($InstallDir)) {
$InstallDir = Join-Path $HOME ".claude"
}
$TargetFile = Join-Path $InstallDir "statusline.exe"
$SettingsFile = Join-Path $HOME ".claude\settings.json"
$TomlFile = Join-Path $InstallDir "statusline.toml"
$DefaultInstallDir = Join-Path $HOME ".claude"
if ($InstallDir -eq $DefaultInstallDir) {
$CommandPath = "~/.claude/statusline.exe"
} else {
$CommandPath = $TargetFile
}
# ── Output helpers ─────────────────────────────────────────────────────────────
function Write-Success([string]$Msg) {
Write-Host -NoNewline -ForegroundColor Green "✓"
Write-Host " $Msg"
}
function Write-Info([string]$Msg) {
Write-Host -NoNewline -ForegroundColor Cyan "→"
Write-Host " $Msg"
}
function Write-Warn([string]$Msg) {
Write-Host -NoNewline -ForegroundColor Yellow "⚠" -ErrorAction SilentlyContinue
[Console]::Error.WriteLine(" $Msg")
}
function Write-Err([string]$Msg) {
Write-Host -NoNewline -ForegroundColor Red "✗" -ErrorAction SilentlyContinue
[Console]::Error.WriteLine(" $Msg")
}
function Write-Step([int]$N, [string]$Msg) {
Write-Host ""
Write-Host -NoNewline -ForegroundColor Cyan "[$N/3]"
Write-Host " $Msg"
}
# ── Header / footer ────────────────────────────────────────────────────────────
function Print-Header {
Write-Host ""
Write-Host "╔══════════════════════════════════════════════════╗"
Write-Host "║ Claude Code Statusline - Installer ║"
Write-Host "╚══════════════════════════════════════════════════╝"
Write-Host ""
}
function Print-Footer {
Write-Host ""
Write-Host "╔══════════════════════════════════════════════════╗"
Write-Host "║ Installation Complete! ║"
Write-Host "╚══════════════════════════════════════════════════╝"
Write-Host ""
Write-Host "Installed: $TargetFile"
Write-Host ""
Write-Host -NoNewline "Next step: "
Write-Host -ForegroundColor Cyan "Restart Claude Code to see your new statusline"
Write-Host ""
Write-Host "To update, run the installation command again."
Write-Host "To customize, edit $TomlFile"
Write-Host ""
}
# ── Download with retries ──────────────────────────────────────────────────────
function Download-WithRetries([string]$Url, [string]$Dest) {
$attempt = 1
while ($attempt -le $MaxRetries) {
try {
$prev = $ProgressPreference
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri $Url -OutFile $Dest -UseBasicParsing
$ProgressPreference = $prev
return $true
} catch {
$ProgressPreference = $prev
$attempt++
if ($attempt -le $MaxRetries) { Start-Sleep -Seconds 1 }
}
}
return $false
}
# ── Main ───────────────────────────────────────────────────────────────────────
Print-Header
# [1/3] Check dependencies
Write-Step 1 "Checking dependencies..."
$Missing = @()
foreach ($dep in @("claude")) {
if (-not (Get-Command $dep -ErrorAction SilentlyContinue)) {
$Missing += $dep
}
}
if ($Missing.Count -gt 0) {
Write-Err "Missing dependencies: $($Missing -join ', ')"
Write-Host ""
if ($Missing -contains "claude") {
Write-Host -NoNewline -ForegroundColor Cyan "Claude Code CLI:"
Write-Host ""
Write-Host " Visit https://claude.ai/code for installation instructions"
Write-Host ""
}
Write-Host "Installation aborted. Install dependencies and try again."
exit 1
}
foreach ($dep in @("claude")) {
$ver = & $dep --version 2>$null | Select-Object -First 1
if ([string]::IsNullOrWhiteSpace($ver)) { $ver = "found" }
Write-Success "$dep $ver"
}
# [2/3] Install binary
Write-Step 2 "Installing binary..."
$Asset = "statusline-windows-x64.exe"
if (-not [string]::IsNullOrEmpty($Version)) {
$Tag = $Version
} else {
$ProgressPreference = 'SilentlyContinue'
try {
$Release = Invoke-RestMethod -Uri $GithubApi -UseBasicParsing
} catch {
Write-Err "Could not determine latest release tag."
exit 1
} finally {
$ProgressPreference = 'Continue'
}
$Tag = $Release.tag_name
if ([string]::IsNullOrEmpty($Tag)) {
Write-Err "Could not determine latest release tag."
exit 1
}
}
Write-Info "Downloading statusline $Tag for $Asset..."
if (-not (Test-Path $InstallDir)) {
try {
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
} catch {
Write-Err "Cannot create install directory: $InstallDir"
exit 1
}
}
$DownloadUrl = "$GithubDlBase/$Tag/$Asset"
if (-not (Download-WithRetries $DownloadUrl $TargetFile)) {
Write-Err "Failed to download from $DownloadUrl"
Write-Info "Check your internet connection and try again"
exit 1
}
if (-not (Test-Path $TargetFile) -or (Get-Item $TargetFile).Length -eq 0) {
Write-Err "Downloaded file is empty"
exit 1
}
Write-Info "Verifying checksum..."
$ChecksumsUrl = "$GithubDlBase/$Tag/checksums.txt"
$ChecksumsTmp = Join-Path $env:TEMP "statusline-checksums-$([System.IO.Path]::GetRandomFileName()).txt"
if (-not (Download-WithRetries $ChecksumsUrl $ChecksumsTmp)) {
Write-Err "Failed to download checksums.txt — cannot verify binary integrity"
Remove-Item -Force $TargetFile -ErrorAction SilentlyContinue
exit 1
}
$ChecksumsContent = Get-Content $ChecksumsTmp -ErrorAction SilentlyContinue
Remove-Item -Force $ChecksumsTmp -ErrorAction SilentlyContinue
$ExpectedLine = $ChecksumsContent | Where-Object { $_ -match " $([regex]::Escape($Asset))$" } | Select-Object -First 1
if ([string]::IsNullOrEmpty($ExpectedLine)) {
Write-Err "Checksum not found for $Asset in checksums.txt"
Remove-Item -Force $TargetFile -ErrorAction SilentlyContinue
exit 1
}
$ExpectedHash = ($ExpectedLine -split '\s+')[0].ToUpper()
$ActualHash = (Get-FileHash $TargetFile -Algorithm SHA256).Hash.ToUpper()
if ($ActualHash -ne $ExpectedHash) {
Write-Err "Checksum mismatch for $Asset"
Write-Err " expected: $ExpectedHash"
Write-Err " got: $ActualHash"
Remove-Item -Force $TargetFile -ErrorAction SilentlyContinue
exit 1
}
Write-Success "Checksum verified"
if (Test-Path $TomlFile) {
Write-Info "Config already exists, skipping: $TomlFile"
} else {
try {
& $TargetFile --print-defaults | Set-Content -Path $TomlFile -Encoding UTF8
Write-Success "Created default config: $TomlFile"
} catch {
Write-Err "Failed to generate $TomlFile"
exit 1
}
}
Write-Success "Binary installed to $TargetFile"
# [3/3] Configure Claude Code
Write-Step 3 "Configuring Claude Code..."
$cfgExit = 0
try {
& $TargetFile --configure-settings $SettingsFile $CommandPath
$cfgExit = $LASTEXITCODE
} catch {
$cfgExit = 1
}
if ($cfgExit -ne 0) {
Write-Warn "Installation succeeded, but automatic configuration failed"
Write-Host ""
Write-Host "Please manually add to ~/.claude/settings.json:"
Write-Host ' {'
Write-Host ' "statusLine": {'
Write-Host ' "type": "command",'
Write-Host " `"command`": `"$CommandPath`","
Write-Host ' "padding": 0'
Write-Host ' }'
Write-Host ' }'
Write-Host ""
exit 2
}
Print-Footer