How to clear bell state from all tmux windows

I support a large number of Unix-like servers and therefore support a script called tmux-rebuildthat I use to rebuild all tmux sessions and windows with SSH links to each server.

I have tmux to show the window name in red with an exclamation mark in the status bar when a bell symbol is printed in this window. This is very convenient for programs such as irssiwarning me when I have messages in another window.

I also have mine $PS1configured on each server to print a terminal bell at the end of each invitation. This is useful because if I run a long job in one window and switch to another, I can immediately see when it will end, because when my invitation is written to the screen after the job is completed, tmux makes the window name red, an exclamation mark. This is great for my workflow.

However, this causes a slight problem with the rebuild script mentioned above, because when I run tmux after it starts, every window in each session is marked in red since the first prompt is printed on the screen. This makes the function useless until I look in every window, and there is something like 40-50 of them.

Is there something I can add to my script that will clear all warnings from sessions and windows after they are created? I do not mind using kludge if necessary.

+5
source share
3 answers

An acceptable workaround has been identified; I redefined the following / previous bindings to allow retries:

# Allow repeats for next/prev window
bind-key -r n next-window
bind-key -r p previous-window

This allows me to quickly notice warnings for all windows in a session by pressing my prefix key and pressing "n" until they become clear and I will return to my original window.

+5
source

With tmux 1.6 (and later) it list-windowscan generate custom output, so it’s pretty easy to read the output lines and create a loop that runs select-windowfor each window.

list-session ( , ) display-message ( / "" , ), - :

#!/bin/sh

# usage: tmux-select-each [session [...]]
#
# Select every window in specified session(s). If no sessions are
# specified, process all windows in all sessions.
#
# This can be handy for clearing the activity flags of windows in
# freshly spawned sessions.

if test $# -gt 0; then
    for session; do
        tmux display-message -p -t "$session:" '#S'
    done
else
    tmux list-sessions -F '#{session_name}'
fi |
while read -r session; do
    active_window=$(tmux display-message -p -t "$session:" '#S:#I')
    last_window=$(tmux display-message -p -t "$session:"\! '#S:#I' 2>/dev/null)
    tmux list-windows -t "$session" -F '#{session_name}:#{window_index}' |
    while read -r window; do
        if test "$window" = "$active_window" ||
           test "$window" = "$last_window"; then
            continue
        fi
        tmux select-window -t "$window"
    done
    if [ -n "$last_window" ]; then
        tmux select-window -t "$last_window"
    fi
    tmux select-window -t "$active_window"
done
+4

On the tmux man page, specifically the last sentence here:

kill-session [-aC] [-t target-session]
          Destroy the given session, closing any windows linked to it
          and no other sessions, and detaching all clients attached 
          to it.  If -a is given, all sessions but the specified one is
          killed.  The -C flag clears alerts (bell, activity, or
          silence) in all windows linked to the session.

So simple:

kill-session -C
+1
source

All Articles