0

On my VPN server, I have some scripts that I run in separate windows, and I'd like to step through them every few seconds like the GIF below.

enter image description here

Is there an existing tmux binding or one I could create that, when activated, will step through the open windows (not panes) of a tmux session? Even if it was a macro of sorts that executed the keystroke below in a loop would be fine. I'd also like to use the same binding to stop stepping through the windows.

Ctrl+b, n, (wait 3 seconds)

1 Answer 1

2

You can write your own small shell script to do this. For example, create file mytmux somewhere in your PATH and make it executable chmod +x mytmux, with these contents:

#!/bin/bash
rotate(){
        file=/tmp/mytmux.$session
        if [ -f "$file" ]
        then rm "$file"
        else touch "$file"
             while [ -f "$file" ] && tmux next-window -t "$session"
             do     sleep 3
             done
        fi
}
case $1 in
-rotate)shift
        session=${1?session name}
        rotate ;;
esac

I made it take an argument -rotate in case you add other helper routines later. To your ~/.tmux.conf add a suitable binding, eg:

bind-key C run-shell -b 'mytmux -rotate #{session_name}'

The -b is to run in the background. The first time you type control-bC the tmp file does not exist, so the while loop runs issuing a next-window command every 3 seconds. The second time the tmp file is removed, and the first script will stop. You should wait 3 seconds before starting again or you may end up with 2 scripts running!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .