Last active
December 18, 2015 15:28
-
-
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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