Skip to content

Instantly share code, notes, and snippets.

@jpmens
Created April 5, 2019 22:36
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jpmens/b3d976bc9e3449f3310f379f0d1c5583 to your computer and use it in GitHub Desktop.
Save jpmens/b3d976bc9e3449f3310f379f0d1c5583 to your computer and use it in GitHub Desktop.
tmux autostart via ssh
# .profile
...
# try to attach to tmux session or create a new one. When
# tmux exits (e.g. detach) we exit this session.
sname="t-$(hostname)"
if [[ -z "$TMUX" ]] && [ "$SSH_CONNECTION" != "" ]; then
tmux attach-session -t $sname || tmux new-session -s $sname
exit
fi
@jpmens
Copy link
Author

jpmens commented Apr 6, 2019

@dne
Copy link

dne commented Apr 6, 2019

Note that line 11 can be simplified using the -A flag for for new-session.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment