Skip to content

Instantly share code, notes, and snippets.

@thelinuxkid
Last active December 18, 2015 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thelinuxkid/5804111 to your computer and use it in GitHub Desktop.
Save thelinuxkid/5804111 to your computer and use it in GitHub Desktop.
Automatically open tmux when ssh'ing into a server if the LC_TMUX variable has been set by the ssh client, e.g., ssh -o SendEnv=LC_TMUX user@server. If a session does not exist then a new one is created. Otherwise, the last session is attached. This should always be run last either in .bashrc or as a script in .bashrc.d. The user is logged out f…
# This script should be the last one run in .bashrc.d. Run if
# the LC_TMUX variable has been set by the ssh client, e.g.,
# ssh -o SendEnv=LC_TMUX user@server.
if [[ -z "$TMUX" ]] && [[ -n "$LC_TMUX" ]]; then
tmux has-session &> /dev/null
if [ $? -eq 1 ]; then
exec tmux new
exit
else
exec tmux attach
exit
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment