Set the default-command
option for the session to run your shell (I'll assume it is bash
) with the --rcfile
option to use your shell script as the initialization file
set-option -g default-command "bash --rcfile yourscript.sh"
Since --rcfile
replaces .bashrc
, you add source .bashrc
to the beginning of yourscript.sh
. If you would ordinarily start a login shell in a tmux
window, add source .bash_profile
instead.
To have separate default commands for different sessions, you need to create the session first, then set its default command.
tmux new-session -s projectA
tmux set-option -s -t projectA default-command "bash --rcfile projectA.sh"
You might want to define a shell function to simplify setting up a new session, something like
new_session () {
tmux new-session -s "$1"
tmux set-option -s -t "$1" default-command "bash --rcfile $1.sh"
}