disable agent tracker in left tmux status

This commit is contained in:
David Chen 2025-12-21 15:36:21 -08:00
parent 3602e03a67
commit 9188c9fdd1
4 changed files with 32 additions and 168 deletions

View file

@ -276,20 +276,20 @@ set-option -g status-right "#(~/.config/tmux/tmux-status/right.sh)"
# session index switching # session index switching
bind -n C-1 run-shell "~/.config/tmux/scripts/switch_session_by_index.sh 1" bind -n C-1 run-shell -b "~/.config/tmux/scripts/switch_session_by_index.sh 1"
bind -n C-2 run-shell "~/.config/tmux/scripts/switch_session_by_index.sh 2" bind -n C-2 run-shell -b "~/.config/tmux/scripts/switch_session_by_index.sh 2"
bind -n C-3 run-shell "~/.config/tmux/scripts/switch_session_by_index.sh 3" bind -n C-3 run-shell -b "~/.config/tmux/scripts/switch_session_by_index.sh 3"
bind -n C-4 run-shell "~/.config/tmux/scripts/switch_session_by_index.sh 4" bind -n C-4 run-shell -b "~/.config/tmux/scripts/switch_session_by_index.sh 4"
bind -n C-5 run-shell "~/.config/tmux/scripts/switch_session_by_index.sh 5" bind -n C-5 run-shell -b "~/.config/tmux/scripts/switch_session_by_index.sh 5"
bind -n C-6 run-shell "~/.config/tmux/scripts/switch_session_by_index.sh 6" bind -n C-6 run-shell -b "~/.config/tmux/scripts/switch_session_by_index.sh 6"
bind -n C-7 run-shell "~/.config/tmux/scripts/switch_session_by_index.sh 7" bind -n C-7 run-shell -b "~/.config/tmux/scripts/switch_session_by_index.sh 7"
bind -n C-8 run-shell "~/.config/tmux/scripts/switch_session_by_index.sh 8" bind -n C-8 run-shell -b "~/.config/tmux/scripts/switch_session_by_index.sh 8"
bind -n C-9 run-shell "~/.config/tmux/scripts/switch_session_by_index.sh 9" bind -n C-9 run-shell -b "~/.config/tmux/scripts/switch_session_by_index.sh 9"
bind -n F1 run-shell "~/.config/tmux/scripts/switch_session_by_index.sh 1" bind -n F1 run-shell -b "~/.config/tmux/scripts/switch_session_by_index.sh 1"
bind -n F2 run-shell "~/.config/tmux/scripts/switch_session_by_index.sh 2" bind -n F2 run-shell -b "~/.config/tmux/scripts/switch_session_by_index.sh 2"
bind -n F3 run-shell "~/.config/tmux/scripts/switch_session_by_index.sh 3" bind -n F3 run-shell -b "~/.config/tmux/scripts/switch_session_by_index.sh 3"
bind -n F4 run-shell "~/.config/tmux/scripts/switch_session_by_index.sh 4" bind -n F4 run-shell -b "~/.config/tmux/scripts/switch_session_by_index.sh 4"
bind -n F5 run-shell "~/.config/tmux/scripts/switch_session_by_index.sh 5" bind -n F5 run-shell -b "~/.config/tmux/scripts/switch_session_by_index.sh 5"
# True color support # True color support
set -g default-terminal "tmux-256color" set -g default-terminal "tmux-256color"
set -as terminal-features ",*256col*:RGB" set -as terminal-features ",*256col*:RGB"

View file

@ -86,6 +86,7 @@ def command_switch(index_str: str) -> None:
if index > len(sessions): if index > len(sessions):
return return
run_tmux(["switch-client", "-t", sessions[index - 1]["id"]], check=False) run_tmux(["switch-client", "-t", sessions[index - 1]["id"]], check=False)
run_tmux(["refresh-client", "-S"], check=False)
def command_rename(label: str) -> None: def command_rename(label: str) -> None:

View file

@ -6,4 +6,10 @@ if [[ -z "$index" || ! "$index" =~ ^[0-9]+$ ]]; then
exit 0 exit 0
fi fi
python3 "$HOME/.config/tmux/scripts/session_manager.py" switch "$index" # Get session matching index prefix (e.g., "1-" for index 1)
target=$(tmux list-sessions -F '#{session_id} #{session_name}' 2>/dev/null | awk -v idx="$index" '$2 ~ "^"idx"-" {print $1; exit}')
if [[ -n "$target" ]]; then
tmux switch-client -t "$target"
tmux refresh-client -S
fi

View file

@ -4,21 +4,15 @@ set -euo pipefail
current_session_id="${1:-}" current_session_id="${1:-}"
current_session_name="${2:-}" current_session_name="${2:-}"
detect_current_session_id=$(tmux display-message -p '#{session_id}') # Single tmux call to get all needed info
detect_current_session_name=$(tmux display-message -p '#{session_name}') IFS=$'\t' read -r detect_session_id detect_session_name term_width status_bg < <(
tmux display-message -p '#{session_id} #{session_name} #{client_width} #{status-bg}' 2>/dev/null || echo ""
)
if [[ -z "$current_session_id" ]]; then [[ -z "$current_session_id" ]] && current_session_id="$detect_session_id"
current_session_id="$detect_current_session_id" [[ -z "$current_session_name" ]] && current_session_name="$detect_session_name"
fi [[ -z "$status_bg" || "$status_bg" == "default" ]] && status_bg=black
term_width="${term_width:-100}"
if [[ -z "$current_session_name" ]]; then
current_session_name="$detect_current_session_name"
fi
status_bg=$(tmux show -gqv status-bg)
if [[ -z "$status_bg" || "$status_bg" == "default" ]]; then
status_bg=black
fi
inactive_bg="#373b41" inactive_bg="#373b41"
inactive_fg="#c5c8c6" inactive_fg="#c5c8c6"
@ -28,22 +22,9 @@ separator=""
left_cap="█" left_cap="█"
max_width=18 max_width=18
# width-based label policy: when narrow (<80 cols by default),
# show title for active session and only the numeric index for inactive ones.
left_narrow_width=${TMUX_LEFT_NARROW_WIDTH:-80} left_narrow_width=${TMUX_LEFT_NARROW_WIDTH:-80}
term_width=$(tmux display-message -p '#{client_width}' 2>/dev/null || true)
if [[ -z "${term_width:-}" || "$term_width" == "0" ]]; then
term_width=$(tmux display-message -p '#{window_width}' 2>/dev/null || true)
fi
if [[ -z "${term_width:-}" || "$term_width" == "0" ]]; then
term_width=${COLUMNS:-}
fi
is_narrow=0 is_narrow=0
if [[ -n "${term_width:-}" && "$term_width" =~ ^[0-9]+$ ]]; then [[ "$term_width" =~ ^[0-9]+$ ]] && (( term_width < left_narrow_width )) && is_narrow=1
if (( term_width < left_narrow_width )); then
is_narrow=1
fi
fi
normalize_session_id() { normalize_session_id() {
local value="$1" local value="$1"
@ -69,124 +50,7 @@ extract_index() {
fi fi
} }
tracker_pending_sessions=""
tracker_running_sessions=""
TRACKER_CACHE_DIR="$HOME/.config/tmux/cache"
TRACKER_CACHE_FILE="$TRACKER_CACHE_DIR/tracker_state_lines"
TRACKER_CACHE_TTL=1
file_mtime() {
local path="$1"
[[ ! -e "$path" ]] && return 1
local mtime
mtime=$(stat -f %m "$path" 2>/dev/null || true)
if [[ -n "$mtime" ]]; then
printf '%s\n' "$mtime"
return 0
fi
mtime=$(stat -c %Y "$path" 2>/dev/null || true)
if [[ -n "$mtime" ]]; then
printf '%s\n' "$mtime"
return 0
fi
return 1
}
write_tracker_cache() {
mkdir -p "$TRACKER_CACHE_DIR"
local tmp_file="$TRACKER_CACHE_FILE.$$"
printf '%s\n' "$1" > "$tmp_file"
mv "$tmp_file" "$TRACKER_CACHE_FILE"
}
reset_tracker_state() {
tracker_pending_sessions=""
tracker_running_sessions=""
}
load_tracker_info() {
reset_tracker_state
if ! command -v jq >/dev/null 2>&1; then
return
fi
local tracker_lines=""
local now
now=$(date +%s 2>/dev/null || true)
if [[ -f "$TRACKER_CACHE_FILE" && -n "$now" ]]; then
local cache_mtime
cache_mtime=$(file_mtime "$TRACKER_CACHE_FILE" 2>/dev/null || true)
if [[ -n "$cache_mtime" ]]; then
local age=$(( now - cache_mtime ))
if (( age <= TRACKER_CACHE_TTL )); then
tracker_lines=$(cat "$TRACKER_CACHE_FILE" 2>/dev/null || true)
fi
fi
fi
if [[ -z "$tracker_lines" ]]; then
local tracker_bin="$HOME/.config/agent-tracker/bin/tracker-client"
if [[ ! -x "$tracker_bin" ]]; then
rm -f "$TRACKER_CACHE_FILE" 2>/dev/null || true
return
fi
local tracker_state
tracker_state=$("$tracker_bin" state 2>/dev/null || true)
if [[ -z "$tracker_state" ]]; then
rm -f "$TRACKER_CACHE_FILE" 2>/dev/null || true
return
fi
tracker_lines=$(printf '%s\n' "$tracker_state" | jq -r 'select(.kind == "state") | .tasks[] | "\(.session_id)|\(.status)|\(.acknowledged)"' 2>/dev/null || true)
if [[ -n "$tracker_lines" ]]; then
write_tracker_cache "$tracker_lines"
else
rm -f "$TRACKER_CACHE_FILE" 2>/dev/null || true
return
fi
fi
while IFS='|' read -r session_id status acknowledged; do
[[ -z "$session_id" ]] && continue
case "$status" in
in_progress)
tracker_running_sessions+="$session_id"$'\n'
;;
completed)
if [[ "$acknowledged" == "false" ]]; then
tracker_pending_sessions+="$session_id"$'\n'
fi
;;
esac
done <<< "$tracker_lines"
}
value_in_list() {
local needle="$1"
local list="$2"
if [[ -z "$needle" || -z "$list" ]]; then
return 1
fi
while IFS= read -r line; do
[[ "$line" == "$needle" ]] && return 0
done <<< "$list"
return 1
}
session_has_pending() {
value_in_list "$1" "$tracker_pending_sessions"
}
session_has_running() {
value_in_list "$1" "$tracker_running_sessions"
}
load_tracker_info
sessions=$(tmux list-sessions -F '#{session_id}::#{session_name}' 2>/dev/null || true) sessions=$(tmux list-sessions -F '#{session_id}::#{session_name}' 2>/dev/null || true)
if [[ -z "$sessions" ]]; then if [[ -z "$sessions" ]]; then
@ -232,19 +96,12 @@ while IFS= read -r entry; do
label="${label:0:max_width-1}" label="${label:0:max_width-1}"
fi fi
indicator=""
if session_has_pending "$session_id"; then
indicator=" #[fg=#a6e3a1,bg=${segment_bg}]●#[fg=${segment_fg},bg=${segment_bg}]"
elif session_has_running "$session_id"; then
indicator=" #[fg=#f9e2af,bg=${segment_bg}]●#[fg=${segment_fg},bg=${segment_bg}]"
fi
if [[ -z "$prev_bg" ]]; then if [[ -z "$prev_bg" ]]; then
rendered+="#[fg=${segment_bg},bg=${status_bg}]${left_cap}" rendered+="#[fg=${segment_bg},bg=${status_bg}]${left_cap}"
else else
rendered+="#[fg=${prev_bg},bg=${segment_bg}]${separator}" rendered+="#[fg=${prev_bg},bg=${segment_bg}]${separator}"
fi fi
rendered+="#[fg=${segment_fg},bg=${segment_bg}] ${label}${indicator} " rendered+="#[fg=${segment_fg},bg=${segment_bg}] ${label} "
prev_bg="$segment_bg" prev_bg="$segment_bg"
done <<< "$sessions" done <<< "$sessions"