2

I recently started using tmux. I found I can attach-or-create a tmux session by using:

tmux new-session -A -s main

I was hoping to put this into .profile so that I automatically get put into tmux when I connect via SSH. I'd like to skip this when logging on locally.

I found this question which looks promising, however I'm concerned that if I launch tmux from .profile it'll then launch my shell and create another tmux ad infinitum!

So what's the correct way to avoid launching tmux from .profile if it's already running in tmux?

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232

1 Answers1

5

tmux sets the $TMUX variable to point to the socket, so you can do something like

if [ -z "$TMUX" ]
then
  ....
fi

The stuff inside the test will only be run if the variable is not set - ie you're not already inside a tmux session.