Skip to content

Instantly share code, notes, and snippets.

@James-Firth
Last active July 4, 2024 15:45
Show Gist options
  • Save James-Firth/21a6824cada98985c7d7f6def579cd3b to your computer and use it in GitHub Desktop.
Save James-Firth/21a6824cada98985c7d7f6def579cd3b to your computer and use it in GitHub Desktop.
[Servers] tmux on ssh

On the server, put this snippet in ~/.bashrc to automatically open tmux on ssh

# Open Tmux Session immediately on SSH and exit SSH Session when exiting tmux
if [[ -n "$PS1" ]] && [[ -z "$TMUX" ]] && [[ -n "$SSH_CONNECTION" ]]; then
    tmux attach-session -t ssh_tmux || tmux new-session -s ssh_tmux;
    exit;
fi

Additional Protip:

Add set -sg escape-time 5 to your ~/.tmux.conf and then reload (via <leader> :source-file ~/.tmux.conf) tmux and now mode switching in editors like vim and helix won't be laggy!

Info from https://superuser.com/questions/252214/slight-delay-when-switching-modes-in-vim-using-tmux-or-screen

@James-Firth
Copy link
Author

Combine this with the VS Code Remote-SSH extension for easy VM-based dev

@James-Firth
Copy link
Author

Forget how tmux works? Use this cheatsheet! https://tmuxcheatsheet.com/

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