This is something I've been trying to do too, however I couldn't get your method to work on my setup (LXC containers inside Proxmox). It wouldn't create the initial tmux session.
However, I found this Stack Overflow question which has a useful answer:
I was getting sessions should be nested with care, unset $TMUX to force at the top of tmux when using tmux attach || tmux new. What happens is tmux also executes .bashrc/profile.
So now I use this:
if [[ ! "$TERM" =~ "screen" ]]; then
tmux attach -t default || tmux new -s default
fi
in my .bashrc
TERM is set to 'screen' in tmux environment.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This is something I've been trying to do too, however I couldn't get your method to work on my setup (LXC containers inside Proxmox). It wouldn't create the initial tmux session.
However, I found this Stack Overflow question which has a useful answer:
stackoverflow.com/questions/343253...
Putting
tmux new -A -s mySession
in my .profile works.I'm also using mosh to persist the connection when my PC goes to sleep.
Glad you got it to work, also, I've only heard praises for mosh. I should take it for a spin one of these days.
I was getting
sessions should be nested with care, unset $TMUX to force
at the top of tmux when usingtmux attach || tmux new
. What happens is tmux also executes .bashrc/profile.So now I use this:
if [[ ! "$TERM" =~ "screen" ]]; then
tmux attach -t default || tmux new -s default
fi
in my .bashrc
TERM is set to 'screen' in tmux environment.