if [ $TERM = "xterm" ]; then
( (tmux has-session -t remote && \
tmux attach-session -t remote) || \
(tmux new-session -s remote) ) && exit 0
echo "tmux failed to start"
fi
if [ $TERM = "screen" ]; then
clear
cat /etc/motd
fi
This way tmux gets executed serverside always when I login remotely (e.g. via PuTTY), so my logon session and all running programs are always protected against sudden connectivity breaks. Also I rebind Ctrl+B to Ctrl+A via ~/.tmux.conf.Three keyboard combinations to remember for beginner: Ctrl+A C creates a new window, Ctrl+A D detaches, and Ctrl+A {digit} switches windows. I'm not a power user of tmux, just a few basic features is all I need, but they have changed my server administration habits dramatically.
ctrl+b followed by...
% - split pane vertically
" - split pane horizontally
arrow keys - change pane you're typing in
:new-window
2 - switch to window 2
x - kill pane
d - detach
Command line arguments: tmux list-sessions
tmux attach #will attach to last session by default
tmux attach -t0 #will attach to session 0tmux list-sessions
tmux ls
This is my current configuration: https://gist.github.com/dguaraglia/f15f39f339545041845612a5b...
With that and using tmuxp to manage a context for each of my projects, I can quickly "launch" a project and have a window with an editing pane, a pane to run tests and a pane to run deployment commands/anything else, all of the panes are already using the correct Python virtualenv, etc.
This is a pretty comprehensive cheatsheet: https://gist.github.com/MohamedAlaa/2961058