mirror of
https://github.com/Andre-Bzk/claude-statusline-kit.git
synced 2026-11-15 09:33:04 +01:00
feat: add portable Claude Code statusline kit
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.
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
# cship statusline wrapper
|
||||
# Runs cship, then converts its usage_limits markers (§ 5|7 § pct § reset §)
|
||||
# into progress bars styled identically to the context_bar module.
|
||||
$ErrorActionPreference = 'SilentlyContinue'
|
||||
[Console]::InputEncoding = New-Object System.Text.UTF8Encoding $false
|
||||
[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding $false
|
||||
$OutputEncoding = New-Object System.Text.UTF8Encoding $false
|
||||
|
||||
$cship = Join-Path $env:USERPROFILE '.local\bin\cship.exe'
|
||||
|
||||
# Read the full Claude Code session JSON from stdin, hand it to cship.
|
||||
$inp = [Console]::In.ReadToEnd()
|
||||
$out = $inp | & $cship
|
||||
# Starship's prompt carries a leading blank line (add_newline); drop leading/trailing
|
||||
# blank lines so the statusline doesn't waste a row.
|
||||
$text = ($out -join "`n").Trim("`r", "`n")
|
||||
|
||||
$S = [char]0x00A7
|
||||
$esc = [char]0x1B
|
||||
$rx = [regex]("$S([57])$S([0-9.]+)$S([^$S]*)$S")
|
||||
|
||||
$render = [System.Text.RegularExpressions.MatchEvaluator]{
|
||||
param($m)
|
||||
$type = $m.Groups[1].Value
|
||||
$pct = [double]$m.Groups[2].Value
|
||||
$reset = $m.Groups[3].Value
|
||||
|
||||
$width = 10
|
||||
$filled = [int][math]::Round($pct / 100.0 * $width)
|
||||
if ($filled -lt 0) { $filled = 0 }
|
||||
if ($filled -gt $width) { $filled = $width }
|
||||
$bar = ([string]([char]0x2588) * $filled) + ([string]([char]0x2591) * ($width - $filled))
|
||||
|
||||
# Same thresholds/colors as context_bar: warn >=40 (yellow), critical >=70 (bold red)
|
||||
if ($pct -ge 70) { $color = '1;31' }
|
||||
elseif ($pct -ge 40) { $color = '33' }
|
||||
else { $color = '38;2;125;207;255' }
|
||||
|
||||
if ($type -eq '5') { $label = '⏳ 5h' } else { $label = '📅 7d' }
|
||||
$pctTxt = '{0:0}%' -f $pct
|
||||
$resetTxt = if ([string]::IsNullOrWhiteSpace($reset)) { '' } else { " ($reset)" }
|
||||
|
||||
"$esc[${color}m$label $bar $pctTxt$resetTxt$esc[0m"
|
||||
}
|
||||
|
||||
# Compact the context_window token count marker (§T§<n>§) to K/M form, e.g.
|
||||
# 42329 -> 42.3K. cship has no native thousands formatting, so it's done here.
|
||||
$rxTok = [regex]("${S}T${S}([0-9]+)${S}")
|
||||
$renderTok = [System.Text.RegularExpressions.MatchEvaluator]{
|
||||
param($m)
|
||||
$n = [double]$m.Groups[1].Value
|
||||
$ic = [Globalization.CultureInfo]::InvariantCulture
|
||||
if ($n -ge 1000000) { $v = ($n / 1000000).ToString('0.0', $ic) + 'M' }
|
||||
elseif ($n -ge 1000) { $v = ($n / 1000).ToString('0.0', $ic) + 'K' }
|
||||
else { $v = $n.ToString('0', $ic) }
|
||||
$v -replace '\.0([KM]?)$', '$1'
|
||||
}
|
||||
$text = $rxTok.Replace($text, $renderTok)
|
||||
|
||||
[Console]::Out.Write($rx.Replace($text, $render))
|
||||
Binary file not shown.
@@ -0,0 +1,52 @@
|
||||
# cship — Claude Code statusline (Hero / Recommended + usage progress bars)
|
||||
# Reference: https://cship.dev
|
||||
[cship]
|
||||
lines = [
|
||||
"$starship_prompt",
|
||||
"$cship.model $cship.effort $cship.context_window.total_input_tokens $cship.context_bar $cship.peak_usage $cship.usage_limits",
|
||||
]
|
||||
|
||||
[cship.model]
|
||||
symbol = "🤖 "
|
||||
style = "bold cyan"
|
||||
|
||||
[cship.effort]
|
||||
symbol = "⚡ "
|
||||
style = "fg:#7dcfff"
|
||||
high_style = "fg:#e0af68"
|
||||
xhigh_style = "bold fg:#e0af68"
|
||||
max_style = "bold fg:#f7768e"
|
||||
|
||||
[cship.context_bar]
|
||||
symbol = "🧠 "
|
||||
filled_char = "█"
|
||||
empty_char = "░"
|
||||
format = "[$symbol$value]($style)"
|
||||
width = 10
|
||||
style = "fg:#7dcfff"
|
||||
warn_threshold = 40.0
|
||||
warn_style = "yellow"
|
||||
critical_threshold = 70.0
|
||||
critical_style = "bold red"
|
||||
|
||||
# $value is emitted inside a §T§…§ marker so the statusline wrapper can
|
||||
# compact the raw token count (e.g. 42329 → 42.3K) before display.
|
||||
[cship.context_window.total_input_tokens]
|
||||
symbol = "🔢 "
|
||||
style = "fg:#a9b1d6"
|
||||
format = "[$symbol§T§$value§]($style)"
|
||||
|
||||
# usage_limits emits machine markers (§TYPE§pct§reset§); the statusline wrapper
|
||||
# turns them into progress bars styled like context_bar. Thresholds >100 so cship
|
||||
# adds no ANSI of its own around the markers.
|
||||
[cship.usage_limits]
|
||||
style = ""
|
||||
separator = " "
|
||||
five_hour_format = "§5§{pct}§{reset}§"
|
||||
seven_day_format = "§7§{pct}§{reset}§"
|
||||
warn_threshold = 101
|
||||
critical_threshold = 101
|
||||
|
||||
[cship.peak_usage]
|
||||
symbol = "⏰ "
|
||||
style = "fg:#e0af68"
|
||||
Reference in New Issue
Block a user