Skip to content

Instantly share code, notes, and snippets.

@riscie
Last active March 28, 2023 10:55
Show Gist options
  • Save riscie/47956c7d2c02df01bcfa53d105e7f2a6 to your computer and use it in GitHub Desktop.
Save riscie/47956c7d2c02df01bcfa53d105e7f2a6 to your computer and use it in GitHub Desktop.
automatically start tmux when ssh into a box #zsh #shell
# inside your .bashrc or .zshrc (on the server side) add:
# start tmux if we ssh into the box
if [[ -n "$PS1" ]] && [[ -z "$TMUX" ]] && [[ -n "$SSH_CONNECTION" ]]; then
tmux attach-session -t $USER || tmux new-session -s $USER
fi
# this will attach to an ongoing tmux session or start a new one
# the session name will be the name of the user ($USER)
@riscie
Copy link
Author

riscie commented Mar 28, 2023

Cool, thank you @leenzhu

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