Go back to the main page

Increased Developer Productivity with Tmux, Part 3: Sessions

This article is over 2 years old. Proceed with caution.

Regards ♨ – Minimul

 

 


Understanding Tmux Sessions

In Part 2 I went over my ~/.tmux.conf file. In this installment, I take a peek at another core Tmux element, sessions. Every time Tmux is launched anew it creates a new session. Under the covers, Tmux has a server component that the sessions attach to, a "Mother ship" as it were. It may be confusing at first to learn that Tmux does not launch in stand-alone fashion like say Vim does but the "client-server" design has its advantages. Let's explore Tmux sessions.

  1. To list of all of my current sessions I type tmux list-sessions
  2. It is common for me to have 9 attached sessions as this figure illustrates. I don't like having much more than that as development machine performance can erode.
    Notice these unnamed sessions that only have numbers naming them.
    This section is at the 0:35 mark in the screencast.
  3. If the tmux command with no arguments is executed a new unnamed session will be created.
  4. Just the tmux command alone will create a new session.
    I then detach, <prefix>-d, the session...
    .. and do another tmux list-sessions. See that a new unamed (22) session has been created. Also, notice that its "attached" status is blank since I detached it.
  5. To reattach that session issue a:
  6.   $ tmux attach -t 22
    
    This section is at the 1:18 mark.
    Minimul says —

    You want to be mindful of how many Tmux sessions you have open as it may lead to a decrease in performance. You're like "no duh" but sometimes because a new session and Tmux itself being command-line centric (not a GUI app like Photoshop) we let it fly under the radar when trying to troubleshoot a poorly functioning development machine. Moreover, if you can't open new windows or panes in a current working session it is likely that you need to kill a session or two.

  7. Next, I delete or "kill" this session.
  8. <prefix> <colon> kill-session is executed to kill a session from within a session.
    After killing the session and relisting, the "22" session is no longer present.
  9. Let's run through making a named session.
  10. The command for a named session is e.g. tmux new -s <session-name>
    On the bash command line I type the session name within the newly created named session to make sure when I reattach this is the proper session.
    After detaching and relisting, I confirm that the "new-sesh" session has been appointed.
    Reattaching with tmux attach -t new-sesh. There is the "my-sesh" from figure 9.
    Named sessions are at the 2:20 mark.
  11. Finally, if you want to kill and restart the Tmux "server" issue a:
  12.   $ tmux kill-server
    

That concludes installment 3. Sessions

Understanding sessions is fundamental to wielding the Tmux "sword". In this article and screencast, I reiterate exactly how I use sessions, which will cover the basics. There are more advanced topics that I would have you made aware off, primarily multiple users sharing sessions and running a session within a session.

Next in part 4, I ruminate making Tmux starter templates. While you are waiting for the article check out the screencast that is already baked.

Comment on this article?

If you like this article and screencast go to the dedicated page for this series at http://minimul.com/teaches/tmux.