My current workflow is:
- CTRL+SHIFT+T to launch a new terminal window. That starts a new zsh terminal.
- Type
tmux
to start tmux.
How can I have tmux load by default with a new terminal window?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityThere 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
.
Jun 21, 2012 at 13:37
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
.
Add it to your plugins list then set ZSH_TMUX_AUTOSTART=true
in your .zshrc
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)
Jan 17, 2022 at 11:23
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
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 "tmux" to your .zshrc file, which gets executed every time you start zsh. The quick way:
echo tmux >> ~/.zshrc