Solved Tmux configuration

Very simply, you could run

tmux new-session -d "cmd1"; tmux new-window "cmd2"; tmux new-window "cmd3"; tmux a

You could get more complex with this, notice the commands are contextless and assume the latest session. tmux commands accept targets and more, the man page for tmux is well layed out with all the details and all the commands and their arguments.
 
For the autostart part I use /etc/local.rc and just prefix everything you want to run with tmux. You will also assign it a pane number so you can attach and detach from it or where it is positioned in your screen arrangement.

Example here:
 
As an example I have a script as below to show a few log files.
Code:
#!/bin/sh
tmux new-session -n logs -d 'tail -F /var/log/maillog' \; \
split-window -d 'tail -F /var/log/messages'\; \
split-window -d 'tail -F /var/log/unbound.log'\; \
split-window \; \
select-layout tiled \; \
attach
 
Does tmux have configuration options for starting windows 1,2,3 with specific commands with parameters autostarting in each?
 
Another example. Start a 6-node Redis cluster in six tmux windows. It's for Mac, but should be easy to modify
Code:
#!/bin/bash

# Prerequisites: brew install tmux redis

# Set Session Name
SESSION="Redis local cluster"
SESSIONEXISTS=$(tmux list-sessions 2> /dev/null | grep "$SESSION")

if [ $(uname -p) = "arm" ]
then
    BINPATH="/opt/homebrew/bin"
else
    BINPATH="/usr/local/bin"
fi
CONFIGPATH=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")

# Only create tmux session if it doesn't already exist
if [ "$SESSIONEXISTS" = "" ]
then
    # Start New Session with our name
    tmux new-session -d -s "$SESSION"
    tmux send-keys "cd $CONFIGPATH/7001" C-m "$BINPATH/redis-server $CONFIGPATH/7001/redis.conf" C-m

    CLUSTERCMD="redis-cli --cluster create 127.0.0.1:7001 "
    for i in $(seq 2 6)
    do
        tmux split-window -t "$SESSION"
        tmux send-keys -t "$SESSION" "cd $CONFIGPATH/700$i" C-m "$BINPATH/redis-server $CONFIGPATH/700$i/redis.conf" C-m
        tmux select-layout -t "$SESSION" tiled
        CLUSTERCMD="$CLUSTERCMD 127.0.0.1:700$i "
    done

    CLUSTERCMD="$CLUSTERCMD --cluster-replicas 1"
    echo $CLUSTERCMD
    echo "Run the command above to create the cluster. Only has to be run once."
fi

# Attach Session, on the Main window
tmux attach-session -t "$SESSION"
 
View: https://www.youtube.com/watch?v=-f9rz7joEOA


That showed me more than any other video on tmux, although comments mention:

I think an overview of the key bindings for copy-paste along with some examples of interaction with the system clipboard are required since its a must have feature for anyone using tmux in a productive workflow.

Also this looks useful:-


Also this especially for FreeBSD users.

 
Last edited:
Back
Top