I have this in my .kshrc, can't recall where I found it.
if [ "$PS1" != "" -a "${STARTED_TMUX:-x}" = x -a "${SSH_TTY:-x}" != x ]
then
STARTED_TMUX=1; export STARTED_TMUX
sleep 1
( (tmux has-session -t remote && tmux attach-session -t remote) || (tmux new-session -s remote) ) && exit 0
echo "tmux failed to start"
fi
I also don't recall why the "sleep" command is in there.
Edit: to clarify, this is in the .kshrc of my work machine. When I start xterms on that machine, they just get a normal shell because $SSH_TTY is not set. When I ssh into my work machine from elsewhere, I get attached to the tmux session (if any) or one is started.
It's always seemed like a legacy method of testing to empty string from a time when "" wouldn't be parsed as an argument. Is there any real reason to still do that today?
Edit: to clarify, this is in the .kshrc of my work machine. When I start xterms on that machine, they just get a normal shell because $SSH_TTY is not set. When I ssh into my work machine from elsewhere, I get attached to the tmux session (if any) or one is started.