0

This is in my TmuxHome.sh Script with I can start One Only Tmux Session:

# tmux Start Script Need To Work!!
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 attach || tmux new-session)
fi

okay now i want to example TmuxHome.sh use default .tmux.conf and TmuxWork.sh use tmux-work.conf both enable and run separate sessions. how to go about doing this without problems? Maybe Next TmuxTty.sh or TmuxDev.sh etc...

fine on arch wiki site: https://wiki.archlinux.org/index.php/Tmux it differences now then what it was before

0

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.

  • # TmuxWork.sh: does not work if TmuxHome.sh are running.. # TmuxHome.sh: does not work if TmuxWork are running.. # TmuxSwitch.sh: only work if TmuxWork are already running.. – K.D.G Jan 5 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.