You can simply pass the appropriate arguments to the two tmux calls:
- Pass
tmux the custom config file using the -f argument to tmux itself.
- For
new-session, you should pass the session name using the -s argument.
- For
attach, you pass the session name through -t ("t" for "target").
Putting it all together:
# TmuxWork.sh
if which tmux >/dev/null 2>&1; then
#if not inside a tmux session, and if no session is started, start a new session
test -z "$TMUX" && (
tmux -f ~/.tmux-work.conf attach -t work ||
tmux -f ~/.tmux-work.conf new-session -s work
)
fi
(You probably only need to pass the config file to new-session, since in most cases it doesn't matter for other commands such as attach or commands that run inside the session.)
You can extend this script to actually switch to session "work" if you execute it from inside session "home" or another session, by using the switch-client command:
if test -n "$TMUX" ; then
tmux switch-client -t work
else
tmux attach -t work ||
tmux -f ~/.tmux-work.conf new-session -s work
fi
With some scripting, you might be able to store the session name ("work" in this example) and the custom config file name in shell variables and reuse this snippet to have custom scripts for the many sessions you would like to manage.