21

My current workflow is:

  1. CTRL+SHIFT+T to launch a new terminal window. That starts a new zsh terminal.
  2. Type tmux to start tmux.

How can I have tmux load by default with a new terminal window?

34

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).

  • 2
    Or have different shortcuts for xterm -e tmux and plain xterm. – Nikolai N Fetissov Jun 21 '12 at 13:37
  • Yes, actually I meant it under "I prefer the second way" =) – rush Jun 21 '12 at 13:39
  • 1
    Executing tmux at the end of .zshrc will cause an endless loop of zsh starting tmux starting zsh starting tmux ... – Thor Jun 21 '12 at 14:56
  • How would one go about "modifying terminal launching command"? – eoinoc Jun 22 '12 at 9:04
  • @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. – rush Jun 22 '12 at 9:11
5

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
  • You're missing a space between " and ]. – n.st Apr 9 '14 at 1:17
5

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.

0

Add "tmux" to your .zshrc file, which gets executed every time you start zsh. The quick way:

echo tmux >> ~/.zshrc
  • The 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. – Eksapsy May 12 at 18:16
0

Add this in your ~/.zshrc:

if [ -z $TMUX ]; then; tmux; fi
0

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

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.