Skip to content

Instantly share code, notes, and snippets.

@frostyfrog
Last active December 21, 2015 11:19
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 frostyfrog/6298223 to your computer and use it in GitHub Desktop.
Save frostyfrog/6298223 to your computer and use it in GitHub Desktop.
On login/connection, join an existing tmux session. If none exists, create one. If creating a session fails, drop back to the user's shell. Otherwise, if there weren't any errors, disconnect the user.
# Automatically connect to (or establish) a tmux session
## if we are in a TTY and we aren't in a tmux session and we aren't connected through a gui...
if ( [ -t 1 ] && ! [ -n "$TMUX" ] && [ -z "$DISPLAY" ] ); then
## Attach to tmux, if we fail, start tmux.
## On success, exit the ssh connection.
## On failure, give the user a warning and drop them to the shell
tmux a || tmux
if [ $? -eq 0 ]; then
exit
else
echo "Warning: Unable to connect to tmux, falling back to the normal prompt"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment