I would like to generate a bashrc
configuration file each time I start a particular tmux session, and I want to use my user's default tmux configuration file ${XDG_CONFIG_HOME}/tmux/tmux.conf
as well. This same configuration should be reused with each window/pane created in any given session.
To prevent race conditions when starting multiple sessions simultaneously, I would like to avoid moving/relinking/etc. the default bashrc
/tmux.conf
configuration file each time, as that seems really hairy.
Instead, I am trying to invoke tmux with a dynamic configuration file that performs the following:
- Create a temporary file containing my generated
bashrc
configuration (say,/tmp/bashrc.12345
) - Set the
default-command
option in tmux similar tobash --rcfile /tmp/bashrc.12345 [-i|-l|...] [ARGV...]
(depending on how tmux was invoked) source-file
my user's defaulttmux.conf
This looks similar to the following shell script:
#!/bin/bash
tmuxrc="${XDG_CONFIG_HOME}/tmux/tmux.conf"
bashrc=$( mktemp )
generate-bashrc > "${bashrc}"
# This is the tmux configuration file's final content
config="set-option -g default-command 'bash --rcfile \"${bashrc}\"' ; source-file '${tmuxrc}' ;"
# Reordering the statements makes no apparent difference
#config="source-file '${tmuxrc}' ; set-option -g default-command 'bash --rcfile \"${bashrc}\"' ;"
exec tmux -f <( echo "${config}" ) "${@}"
When running this script, I can see my default tmux configuration file is being loaded, applying my layout/theme and so on, but the default-command
option is definitely not working like I would expect.
Instead, my default shell is started, and when I print the current options in tmux with tmux show -sgwp
, it doesn't list default-command
as being defined at all!
EDIT ≈ Even if I run
tmux set-option -g default-command FOO
(withFOO
being anything at all) from inside the running tmux session, it still remains undefined according totmux show -sgwp
Why is this option not persisting?