Skip to content
Open
Show file tree
Hide file tree
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
14 changes: 12 additions & 2 deletions examples/statusline/statusline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,17 @@ FG_BRIGHT_WHITE="\033[97m"
# Number Highlight Color
NUM_COLOR="${FG_BRIGHT_WHITE}${B}"

# ─── Parse JSON from stdin (Single jq pass for performance) ──────────────────
# ─── Read JSON from stdin (bounded) ──────────────────────────────────────────
# Read stdin with a timeout. If the CLI holds the pipe open without writing
# or closing it, an unbounded `jq`/`cat` read would block until the runner
# kills the script, and repeated kills auto-disable the statusline. On
# timeout or empty input, fall back to `{}` so every field takes its default.
INPUT=""
IFS= read -r -d '' -t 2 INPUT || true
exec 0</dev/null
[ -n "$INPUT" ] || INPUT='{}'

# ─── Parse JSON (Single jq pass for performance) ─────────────────────────────
# Extract all fields in one pass to prevent spawning jq 8 times.
{
read -r STATE
Expand All @@ -54,7 +64,7 @@ NUM_COLOR="${FG_BRIGHT_WHITE}${B}"
(.task_count // 0),
(.model.display_name // ""),
(.terminal_width // 80)
' 2>/dev/null || printf "idle\n0\n\nfalse\nfalse\n0\n0\n0\n\n80\n"
' <<< "$INPUT" 2>/dev/null || printf "idle\n0\n\nfalse\nfalse\n0\n0\n0\n\n80\n"
)"

# ─── Computed Values ─────────────────────────────────────────────────────────
Expand Down
8 changes: 6 additions & 2 deletions examples/title/title.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/bin/bash
set -euo pipefail

# Read JSON payload from stdin
DATA=$(cat)
# Read JSON payload from stdin with a timeout, so a pipe that is held open
# without being written to can't hang the script until the runner kills it.
DATA=""
IFS= read -r -d '' -t 2 DATA || true
exec 0</dev/null
[ -n "$DATA" ] || DATA='{}'

# Extract fields using jq
eval $(echo "$DATA" | jq -r '
Expand Down
Loading