I use this function to setup / resume my tmux sessions. If a session exists with the given name it resumes it, otherwise it creates it:
tm() {
[[ -z "$1" ]] && { echo "usage: tm <session>" >&2; return 1; }
tmux has -t $1 && tmux attach -d -t $1 || tmux new -s $1
}
(N.b. If you use something similar already check you have the -d
flag. This will kill old clients (e.g. ssh connections that died, quitting your terminal before disconnecting) and ensure the window resizes correctly.)