Last active
September 30, 2024 11:26
-
-
Save ThomasLeister/c18fb2666fb0924c6555634892285264 to your computer and use it in GitHub Desktop.
Put this into your .bashrc to auto-start a tmux session after SSH login
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
Put these lines into your server's .bashrc: | |
## | |
## TMUX auto attach | |
## | |
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then # if this is an SSH session | |
if which tmux >/dev/null 2>&1; then # check if tmux is installed | |
if [[ -z "$TMUX" ]] ;then # do not allow "tmux in tmux" | |
ID="$( tmux ls | grep -vm1 attached | cut -d: -f1 )" # get the id of a deattached session | |
if [[ -z "$ID" ]] ;then # if not available create a new one | |
tmux new-session | |
else | |
tmux attach-session -t "$ID" # if available, attach to it | |
fi | |
fi | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment