title: How to create new tmux session if none exists
body: <p>I am trying to figure out how to attach to a <code>tmux session</code> if a named tmux session exists, if not I want to create a new one with the given name.</p>
  
  <p>Currently, I know of a few <code>tmux</code> commands which can partly achieve what I am looking for, but its not clear how to combine them together to get what I am looking for:</p>
  
  <ul>
  <li><code>tmux attach</code> attaches to an automatically existing session - but errors out if no session exists</li>
  <li><code>tmux new</code> creates a new session - but it does so every time, so I can't leave it in my <code>.tmux.conf</code></li>
  <li><code>tmux has-session</code> tests whether a session exists - but I don't know how to stitch it together with the other commands</li>
  </ul>
  
  <p>Thus, I would like to create a tmux script, so that this happens automatically, instead of having to manually create it everytime I need to log into a sessions. </p>
  
  <p>How can I write a automatic script so as to create a new tmux session (if a given session name doesnt exist) or attach to a session name (if it exists)?</p>