Having tmux load by default when a zsh terminal is launched

There are at least two ways:

  1. Write something like

    if [ "$TMUX" = "" ]; then tmux; fi
    

    at the beginning of ~/.zshrc. Note the conditional test to a possible loop when tmux spawns its own zsh.

  2. Modify terminal launching command to something like

    xterm -e tmux
    

I prefer the second way, because sometimes I need to launch a terminal without tmux (for example when I need to reconnect to an existing session).


There is actually a default plugin tmux for oh_my_zsh.

Add it to your plugins list then set ZSH_TMUX_AUTOSTART=true in your .zshrc

For more reference, go here


add it to your .zshrc

if [ -z "$TMUX" ]
then
    tmux attach -t TMUX || tmux new -s TMUX
fi

then tmux will automatically connect to a session called TMUX when you launch your terminal.

Tags:

Terminal

Zsh

Tmux