Having tmux load by default when a zsh terminal is launched
Solution 1
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 whentmux
spawns its ownzsh
. -
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).
Solution 2
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
Solution 3
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.
Solution 4
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
Related videos on Youtube
eoinoc
Updated on September 18, 2022Comments
-
eoinoc over 1 year
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?
-
krasnoff almost 12 yearsOr have different shortcuts for
xterm -e tmux
and plainxterm
. -
rush almost 12 yearsYes, actually I meant it under "I prefer the second way" =)
-
eoinoc almost 12 yearsHow would one go about "modifying terminal launching command"?
-
rush almost 12 years@eoinoc it depends on your environment. For example, I'm using awesome wm, therefore I just need to modify string in my config file. In kde you need to edit hotkeys. And so on.
-
eoinoc almost 12 years@Rush Great, I was able to do it with
gnome-conf
unix.stackexchange.com/questions/41442/… -
n.st about 10 yearsYou're missing a space between
"
and]
. -
x1a0 almost 8 yearsI am really sorry that I down-voted this answer by a misclick - would be nice if down vote can to removed/reset.
-
liz14 about 5 yearsThe thing with this, is that it starts a new session in every new instance and it bloats tmux with sessions that you've never exited (also tmux will complain about it). Not a good solution.
-
RichieHH almost 4 yearsOut of curiosity are you using that now? Doesnt work for me. Have that env set and it doesnt start. tmux definitely added to plugin array,
-
pfincent over 3 yearsIn my setup, the $TMUX variable is not empty even if I'm not inside a tmux session. Executing
echo $TMUX
returns/tmp//tmux-1000/default,1647,2
. Does anybody know why that is or how to adjust the script to make @rush's solution work under these circumstances? -
tbraden over 3 yearsyou have to add the
ZSH...=...
assignment before the linesource $ZSH/oh-my-zsh.sh
, from github.com/ohmyzsh/ohmyzsh/issues/3676#issuecomment-77806736 -
starm3nace over 2 yearsalso add tmux to the list of your plugins in
.zshrc
:plugins=(... tmux)