diff --git a/.tmux.conf b/.tmux.conf index 746573d..018d6a5 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -187,6 +187,7 @@ bind > swap-pane -D bind < swap-pane -U bind | swap-pane bind -n M-b run-shell 'val=$(tmux show -wv @unread 2>/dev/null); if [ "$val" = "1" ]; then tmux set -wu @unread; else tmux set -w @unread 1; fi; tmux refresh-client -S' +bind -n M-w run-shell -b 'val=$(tmux show -wv @watching 2>/dev/null); if [ "$val" = "1" ]; then tmux set -wu @watching; tmux refresh-client -S; else ~/.config/tmux/scripts/watch_pane.sh "#{pane_id}" "#{window_id}"; fi' bind -n M-m run-shell "test -f ~/.config/agent-tracker/scripts/focus_latest_notified.sh && bash ~/.config/agent-tracker/scripts/focus_latest_notified.sh || true" bind -n M-M run-shell "test -f ~/.config/agent-tracker/scripts/focus_last_origin.sh && bash ~/.config/agent-tracker/scripts/focus_last_origin.sh || true" bind Space run-shell "~/.config/tmux/scripts/toggle_orientation.sh" diff --git a/tmux/scripts/watch_pane.sh b/tmux/scripts/watch_pane.sh new file mode 100755 index 0000000..ec448e1 --- /dev/null +++ b/tmux/scripts/watch_pane.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +set -euo pipefail + +pane_id="$1" +window_id="$2" + +[[ -z "$pane_id" || -z "$window_id" ]] && exit 1 + +shells="bash zsh fish sh dash ksh tcsh csh" + +is_shell() { + local cmd="$1" + for s in $shells; do + [[ "$cmd" == "$s" ]] && return 0 + done + return 1 +} + +current_cmd=$(tmux display-message -p -t "$pane_id" '#{pane_current_command}' 2>/dev/null || true) +[[ -z "$current_cmd" ]] && exit 0 + +if is_shell "$current_cmd"; then + exit 0 +fi + +tmux set -w -t "$window_id" @watching 1 2>/dev/null || true +tmux refresh-client -S + +while true; do + sleep 1 + watching=$(tmux show -wv -t "$window_id" @watching 2>/dev/null || true) + [[ "$watching" != "1" ]] && exit 0 + cmd=$(tmux display-message -p -t "$pane_id" '#{pane_current_command}' 2>/dev/null || true) + if [[ -z "$cmd" ]] || is_shell "$cmd"; then + break + fi +done + +tmux set -wu -t "$window_id" @watching 2>/dev/null || true +tmux set -w -t "$window_id" @unread 1 2>/dev/null || true +tmux refresh-client -S diff --git a/tmux/tmux-status/left.sh b/tmux/tmux-status/left.sh index 43e8cac..7e4ea9f 100755 --- a/tmux/tmux-status/left.sh +++ b/tmux/tmux-status/left.sh @@ -70,13 +70,22 @@ fi get_session_icon() { local sid="$1" + # Check for manual @watching on any window in this session + local watching_win + watching_win=$(tmux list-windows -t "$sid" -F '#{@watching}' 2>/dev/null | grep -m1 '^1$' || true) + # Check for manual @unread on any window in this session local unread_win unread_win=$(tmux list-windows -t "$sid" -F '#{@unread}' 2>/dev/null | grep -m1 '^1$' || true) + if [[ -n "$unread_win" ]]; then printf '🔔' return fi + if [[ -n "$watching_win" ]]; then + printf '⏳' + return + fi [[ -z "$tracker_state" ]] && return local result diff --git a/tmux/tmux-status/window_task_icon.sh b/tmux/tmux-status/window_task_icon.sh index b0034f3..67b4d50 100755 --- a/tmux/tmux-status/window_task_icon.sh +++ b/tmux/tmux-status/window_task_icon.sh @@ -4,6 +4,13 @@ set -euo pipefail window_id="$1" [[ -z "$window_id" ]] && exit 0 +# Check manual @watching flag +watching=$(tmux show -wv -t "$window_id" @watching 2>/dev/null || true) +if [[ "$watching" == "1" ]]; then + printf '⏳' + exit 0 +fi + # Check manual @unread flag unread=$(tmux show -wv -t "$window_id" @unread 2>/dev/null || true) if [[ "$unread" == "1" ]]; then