-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoggle.sh
More file actions
executable file
·68 lines (61 loc) · 1.84 KB
/
Copy pathtoggle.sh
File metadata and controls
executable file
·68 lines (61 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
# Toggle the Claude Code iTerm2 tab-color signaling on/off.
#
# toggle.sh # flip current state
# toggle.sh on # force enable
# toggle.sh off # force disable
# toggle.sh status # print current state
#
# Disabling drops a flag file that tab-state.sh checks; while present, every
# hook call clears anything we painted instead of signaling.
set -u
FLAG="${HOME}/.claude/tab-state.disabled"
STATE_DIR="${HOME}/.claude/.tab-state"
RESET_SEQ='\033]6;1;bg;*;default\007'
# Clear every tab we have ever painted. Without this, an idle tab keeps its
# color until it happens to see another hook event, which may be never.
reset_registered_ttys() {
local f dev
for f in "$STATE_DIR"/tty-*; do
[ -e "$f" ] || continue
read -r dev _ 2>/dev/null <"$f" || continue # record is "dev owner state"
if [ -w "$dev" ]; then
printf '%b' "$RESET_SEQ" >"$dev" 2>/dev/null
else
rm -f "$f" # the tty is gone; drop the record
fi
done
}
enable() {
rm -f "$FLAG"
echo "tab-state: ON"
}
disable() {
local f
mkdir -p "${HOME}/.claude" 2>/dev/null
: >"$FLAG"
echo "tab-state: OFF"
reset_registered_ttys
# Subagent tokens too: while off, tab-state.sh never sees the SubagentStop
# that would clear them, so they would strand the tab blue on re-enable.
for f in "$STATE_DIR"/agent-* "$STATE_DIR"/stopped-*; do
[ -e "$f" ] && rm -f "$f"
done
# The current terminal may not be registered yet (no hook has fired in it).
{ printf '%b' "$RESET_SEQ" >/dev/tty; } 2>/dev/null || true
}
status() {
if [ -e "$FLAG" ]; then echo "tab-state: OFF"; else echo "tab-state: ON"; fi
}
case "${1:-toggle}" in
on) enable ;;
off) disable ;;
status) status ;;
toggle)
if [ -e "$FLAG" ]; then enable; else disable; fi
;;
*)
echo "usage: toggle.sh [on|off|toggle|status]" >&2
exit 2
;;
esac