theniceboy/tmux/tmux-status/window_task_icon.sh

37 lines
923 B
Bash
Executable file

#!/usr/bin/env bash
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
printf '🔔'
exit 0
fi
CACHE_FILE="/tmp/tmux-tracker-cache.json"
[[ ! -f "$CACHE_FILE" ]] && exit 0
state=$(cat "$CACHE_FILE" 2>/dev/null || true)
[[ -z "$state" ]] && exit 0
result=$(echo "$state" | jq -r --arg wid "$window_id" '
.tasks // [] | .[] | select(.window_id == $wid) |
if .status == "in_progress" then "in_progress"
elif .status == "completed" and .acknowledged != true then "waiting"
else empty end
' 2>/dev/null | head -1 || true)
case "$result" in
in_progress) printf '⏳' ;;
waiting) printf '🔔' ;;
esac