As I went into a little bit in my previous post, I have recently been taking another crack at working in tmux, after a less than stellar first crack at it a couple of months ago. One of my inital problems with tmux was that it was annoying to try and keep track of what sessions I had open and in which directories. The default naming scheme for sessions is just to assign each one a number unless you manually rename it.

So I would have to go through the steps each time of 1) opening Terminal 2) running “tmux ls” to see if I had any existing sesions open then (this is if I remember to) then having to either 3) run “tmux a -t ”, which normally takes a couple of attempts because I can’t remember the order of arguments, or I would get the name wrong, or 4) I would start a new session (which only adds to the mess) and remember to either 5) set the name when I created the session or 5) set the name once the session attached.


Luckily, Thoughtbot and thier incredible repo dotfiles has a solution for this exact problem. Included in the bin directory, is a shell script called tat. When you run tat, the script will “Attach or create tmux session named the same as current directory.” This is great. Now, if you want to attach to a tmux session, all you do is run one command “tat” and either you pick up where you left off in an existing sesion, or you get a new one, with the correct name and everything. Then using the session switcher (which I bind to s) you can easily switch between all the directories you have open.

The last piece of the puzzle is that I added a small script to my zshrc.local file to make sure that whenever I open a new shell, if I am not currently attached to a tmux session, tat will get called.

_not_inside_tmux() { [[ -x "$TMUX" ]] }

ensure_tmux_is_running() {
  if _not_inside_tmux; then


And that is that. Whenever I open a new shell, I get thrown into a tmux session right away. This effectively eliminates the friction I was feeling with creating and managing tmux sessions.