My current workflow is:
- CTRL+SHIFT+T to launch a new terminal window. That starts a new zsh terminal.
- Type
tmuxto start tmux.
How can I have tmux load by default with a new terminal window?
There are at least two ways:
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.
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).
xterm -e tmux and plain xterm.
tmux at the end of .zshrc will cause an endless loop of zsh starting tmux starting zsh starting tmux ...
There is actually a default plugin tmux for oh_my_zsh.
ZSH_TMUX_AUTOSTART=true in your .zshrcsource $ZSH/oh-my-zsh.sh
(cf. this comment on GitHub).For more reference, go here
ZSH...=... assignment before the line source $ZSH/oh-my-zsh.sh, from github.com/ohmyzsh/ohmyzsh/issues/3676#issuecomment-77806736
.zshrc: plugins=(... tmux)
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.
Be careful with the echo tmux >> ~/.zshrc solution though, I remember
that simply throwing a bash in a .cshrc file caused me trouble over SSH.
IIRC the problem occurred with non-interactive shells, so you should test for that.
case $- in *i*)
if [ -z "$TMUX" ]; then exec tmux; fi;;
esac
" and ].
My compromise is to automatically start tmux if no sessions are running.
This way, only the first terminal window starts tmux. A following windows do not start tmux and you can decide to attach to a session or to not use tmux at all there.
To do so add the following at the beginning of ~/.zshrc:
if [[ ! $(tmux list-sessions) ]]; then
tmux
fi
Add this in your ~/.zshrc:
if [ -z $TMUX ]; then; tmux -t TMUX || tmux new -s TMUX; fi
Add "tmux" to your .zshrc file, which gets executed every time you start zsh. The quick way:
echo tmux >> ~/.zshrc