Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion examples/statusline/statusline.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
#!/bin/bash
set -euo pipefail

# ─── stdin timeout guard ──────────────────────────────────────────────────────
# The CLI's statusline runner hard-kills this script (~5-10s) if it never
# returns. During auth/OAuth refresh or resume-conversation warm-up, stdin can
# be held open by the runner without being written to or closed, so an
# unbounded `jq`/`cat` read on stdin hangs until SIGKILL — and enough
# consecutive kills auto-disables the custom statusline. Read stdin with a
# short timeout up front and close it immediately after, so the rest of the
# script never blocks on it.
run_with_timeout() {
local t="$1"
shift
if command -v timeout >/dev/null 2>&1; then
timeout --foreground "$t" "$@"
else
"$@" <&0 &
local pid=$!
( sleep "$t"; kill "$pid" 2>/dev/null || true ) &
local killer=$!
wait "$pid" 2>/dev/null
local res=$?
kill "$killer" 2>/dev/null || true
wait "$killer" 2>/dev/null || true
return $res
fi
}

JSON_INPUT=$(run_with_timeout 0.25 cat 2>/dev/null || true)
exec 0</dev/null
if [ -z "$JSON_INPUT" ]; then
JSON_INPUT="{}"
fi

# ─── ANSI Helpers (Standard 16-color palette only) ───────────────────────────
R="\033[0m" # Reset
B="\033[1m" # Bold
Expand Down Expand Up @@ -43,7 +75,7 @@ NUM_COLOR="${FG_BRIGHT_WHITE}${B}"
read -r MODEL
read -r COLS
} <<< "$(
jq -r '
printf '%s' "$JSON_INPUT" | jq -r '
(.agent_state // "idle"),
(.context_window.used_percentage // 0),
(.vcs.branch // ""),
Expand Down