How to reload tmux config file which has defined multiple sessions?

Build a wrapper

I think your needs are best served by some form of wrapper script to setup custom sessions. Something like the answer to this one.

It would look something like this, but you should change it for your specific needs.

#!/bin/bash

# test if the session has windows
is_closed(){ 
    sess=$1
    n=$(tmux ls 2> /dev/null | grep "^$sess" | wc -l)
    [[ $n -eq 0 ]]
}

# either create it or attach to it
if is_closed logi ; then
  tmux new -d -s logi -n cmd
  tmux neww -t logi -n logi "cat /dev/logi | ccze -m ansi -p syslog -C"
  tmux splitw -t logi:1 -v -p 50
  tmux selectw -t logi:2
  tmux selectp -t logi:1
fi
if is_closed standard ; then
  tmux new -d -s standard -n htop "htop"
  tmux neww -n cmd -t standard
  tmux splitw -t standard:2 -v -p 50
  tmux selectw -t standard:2 
  tmux selectp -t standard:1
fi

To reload a configuration file

If you make an edit to the configuration file while using tmux, you can run this is the prompt

tmux source-file /path/to/conf

Or, you can bind it to a key in .tmux.conf

bind r source-file ${HOME}/.tmux.conf \; display-message "source-file reloaded"

Home directory configurations

Finally, you really shouldn't be adding significant customizations to /etc/tmux.conf because this would be unhelpful to others if you need to use a shared system. Instead, I suggest you add any customization to ~/.tmux.conf because it's local and specific to your personal needs.


You don't have to use a wrapper script, you can do it with the source-file command.

I split my .tmux.conf in two pieces, and it only source those:

source-file ~/.config/tmux/options.conf
source-file ~/.config/tmux/session.conf

Then, session.conf contains the pane definitions:

new -s logi -n cmd
neww -n logi "cat /dev/logi | ccze -m ansi -p syslog -C"
splitw -t 1 -v -p 50
selectw -t 2
selectp -t 0

new -s standard -n htop "htop"
neww -n cmd
splitw -t 2 -v -p 50
selectw -t 2 
selectp -t 1

And options.conf only contains the option definitions:

bind R source-file ~/.config/tmux/options.conf \; display-message "Config reloaded..."
set -g base-index 1

This way, the bind R can only source the options.conf and everything will be reloaded, but no new panes will be created.
One small drawback is that if you want to change window layout, you need to quit and start a new session.