Use as part of a
~/.zshrc (or similar) to have your shell automatically attach itself to the running
tmux session for your user, or create one if none exist.
But only if not already inside a session & not logged in via SSH.
tmux panes from attempting to nest
tmux sessions, and prevents a
tmus session from being started when SSH-ing into a machine sharing a similar
if [[ "$TERM" != "screen" ]] && [[ "$SSH_CONNECTION" == "" ]]; then # Attempt to discover a detached session and attach # it, else create a new session WHOAMI=$(whoami) if tmux has-session -t $WHOAMI 2>/dev/null; then tmux -2 attach-session -t $WHOAMI else tmux -2 new-session -s $WHOAMI fi else # One might want to do other things in this case, # here I print my motd, but only on servers where # one exists # If inside tmux session then print MOTD MOTD=/etc/motd.tcl if [ -f $MOTD ]; then $MOTD fi fi
If one desires that a
tmux session is started for SSH connections, simply replace:
&& [[ "$SSH_CONNECTION" == "" ]]; then