mirror of
https://github.com/Andre-Bzk/claude-statusline-kit.git
synced 2026-11-15 09:33:04 +01:00
Replicating the cship-based statusline across machines meant manually copying three files and hand-editing settings.json with per-user absolute paths — error-prone and slow. Bundling the assets with an idempotent installer that resolves the pwsh path at runtime and merges into an existing settings.json makes rollout a single command per PC.
90 lines
3.8 KiB
PowerShell
90 lines
3.8 KiB
PowerShell
#requires -Version 5.1
|
|
<#
|
|
install.ps1 — Deploys the Claude Code "cship" statusline onto this machine.
|
|
|
|
Idempotent: safe to run repeatedly. Copies the three assets to their target
|
|
locations, auto-detects the local pwsh path, and merges the statusLine block
|
|
into an existing ~/.claude/settings.json without touching other settings.
|
|
#>
|
|
[CmdletBinding()]
|
|
param(
|
|
# Overwrite an existing cship.toml even if one is already present.
|
|
[switch]$Force
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
$assets = Join-Path $PSScriptRoot 'assets'
|
|
|
|
function Write-Step { param($m) Write-Host " $m" -ForegroundColor Cyan }
|
|
function Write-Ok { param($m) Write-Host " OK $m" -ForegroundColor Green }
|
|
function Write-Warn { param($m) Write-Host " !! $m" -ForegroundColor Yellow }
|
|
|
|
Write-Host "`nClaude Code statusline installer" -ForegroundColor White
|
|
|
|
# --- Target locations -------------------------------------------------------
|
|
$localBin = Join-Path $env:USERPROFILE '.local\bin'
|
|
$config = Join-Path $env:USERPROFILE '.config'
|
|
$claude = Join-Path $env:USERPROFILE '.claude'
|
|
foreach ($d in @($localBin, $config, $claude)) {
|
|
New-Item -ItemType Directory -Force -Path $d | Out-Null
|
|
}
|
|
|
|
# --- 1. cship.exe -----------------------------------------------------------
|
|
Copy-Item (Join-Path $assets 'cship.exe') (Join-Path $localBin 'cship.exe') -Force
|
|
Write-Ok "cship.exe -> $localBin"
|
|
|
|
# --- 2. cship.toml (do not clobber a customised config unless -Force) --------
|
|
$tomlTarget = Join-Path $config 'cship.toml'
|
|
if ((Test-Path $tomlTarget) -and -not $Force) {
|
|
Write-Warn "cship.toml already exists, kept as-is (use -Force to overwrite)"
|
|
} else {
|
|
Copy-Item (Join-Path $assets 'cship.toml') $tomlTarget -Force
|
|
Write-Ok "cship.toml -> $config"
|
|
}
|
|
|
|
# --- 3. Wrapper script ------------------------------------------------------
|
|
$wrapperTarget = Join-Path $claude 'cship-statusline.ps1'
|
|
Copy-Item (Join-Path $assets 'cship-statusline.ps1') $wrapperTarget -Force
|
|
Write-Ok "cship-statusline.ps1 -> $claude"
|
|
|
|
# --- 4. Locate pwsh ---------------------------------------------------------
|
|
$pwsh = (Get-Command pwsh -ErrorAction SilentlyContinue).Source
|
|
if (-not $pwsh) {
|
|
$fallback = 'C:\Program Files\PowerShell\7\pwsh.exe'
|
|
if (Test-Path $fallback) {
|
|
$pwsh = $fallback
|
|
} else {
|
|
Write-Warn "PowerShell 7 (pwsh) not found. Install it, then re-run this script."
|
|
Write-Warn " winget install --id Microsoft.PowerShell -e"
|
|
$pwsh = $fallback # write the conventional path so it works once pwsh is installed
|
|
}
|
|
}
|
|
$pwshFwd = $pwsh.Replace('\', '/')
|
|
$wrapperFwd = $wrapperTarget.Replace('\', '/')
|
|
$command = '"{0}" -NoProfile -ExecutionPolicy Bypass -File "{1}"' -f $pwshFwd, $wrapperFwd
|
|
|
|
# --- 5. Merge statusLine into settings.json ---------------------------------
|
|
$settingsPath = Join-Path $claude 'settings.json'
|
|
if (Test-Path $settingsPath) {
|
|
Copy-Item $settingsPath "$settingsPath.bak" -Force
|
|
$settings = Get-Content $settingsPath -Raw | ConvertFrom-Json
|
|
} else {
|
|
$settings = [PSCustomObject]@{}
|
|
}
|
|
|
|
$statusLine = [PSCustomObject]@{ type = 'command'; command = $command }
|
|
if ($settings.PSObject.Properties.Name -contains 'statusLine') {
|
|
$settings.statusLine = $statusLine
|
|
} else {
|
|
$settings | Add-Member -MemberType NoteProperty -Name 'statusLine' -Value $statusLine
|
|
}
|
|
|
|
$settings | ConvertTo-Json -Depth 20 | Set-Content $settingsPath -Encoding UTF8
|
|
Write-Ok "settings.json statusLine wired to detected pwsh"
|
|
|
|
# --- Post-install notes -----------------------------------------------------
|
|
Write-Host "`nDone." -ForegroundColor Green
|
|
Write-Host "Notes:" -ForegroundColor White
|
|
Write-Warn "Use a terminal font with emoji / Nerd-Font glyphs so the icons render (Cascadia Code, JetBrainsMono Nerd Font, ...)."
|
|
Write-Host " Restart Claude Code (or start a new session) to see the statusline.`n"
|