← back to Terminal Status
verification/install/before/.agents/skills/color/scripts/repaint-dot.sh
37 lines
#!/usr/bin/env bash
set -u
tty_path=""
process_id=$$
for _ in 1 2 3 4 5 6 7 8 9 10; do
line="$(ps -o ppid=,tty= -p "$process_id" 2>/dev/null)" || break
set -- $line
parent_id="${1:-}"
tty_name="${2:-}"
[[ -z "$parent_id" ]] && break
if [[ "$tty_name" == ttys* ]]; then tty_path="/dev/$tty_name"; break; fi
process_id="$parent_id"
done
[[ -n "$tty_path" ]] || exit 0
state_file="${HOME}/.codex/tab-dots/$(basename "$tty_path").dot"
[[ -f "$state_file" ]] || exit 0
title="$(cat "$state_file")"
case "$title" in
🟢*) rgb="0 200 83" ;;
🟡*) rgb="255 204 0" ;;
🟣*) rgb="148 0 211" ;;
🟠*) rgb="255 140 0" ;;
🩷*) rgb="255 105 180" ;;
*) exit 0 ;;
esac
set -- $rgb
{
printf '\033]6;1;bg;red;brightness;%d\007' "$1"
printf '\033]6;1;bg;green;brightness;%d\007' "$2"
printf '\033]6;1;bg;blue;brightness;%d\007' "$3"
printf '\033]1;%s\007' "$title"
printf '\033]2;%s\007' "$title"
printf '\033]1337;SetBadgeFormat=%s\a' "$(printf '%s' "$title" | base64 | tr -d '\n')"
} > "$tty_path" 2>/dev/null