Skip to content

Instantly share code, notes, and snippets.

Last active February 25, 2022 09:28
Show Gist options
  • Save unbracketed/6027277 to your computer and use it in GitHub Desktop.
Save unbracketed/6027277 to your computer and use it in GitHub Desktop.
Using Tmux Sessions for Managing Multiple Project / Computing Workspaces

Some fellow Tmux users I spoke with weren't using the Sessions feature, which I think is one of the coolest features of Tmux. No faulting the Tmux developers for very complete documentation, but it can take a few read-throughs for some of us before the core architecture becomes clear:

  1. The Tmux Server is a collection of Sessions.
  2. A Session is a collection of Windows.
  3. A Window is a collection of Panes which visually subdivide it in the terminal.
  4. Windows and Panes can be moved and shared between Windows, including Windows in other Sessions.

Having used a modern web browser, you already understand principles 1-3. You can open multiple browser windows (Tmux Session), each browser window has multiple tabs (Tmux Window), and each tab has a web page which probably contains multiple visual sections (Tmux Pane).

Using these principles you can easily build up different kinds of shell environments that group tools and views together logically for different kinds of problems you might work on.

Example Use Cases:

  • If you are working on multiple projects (open source / personal / work / whatever) you can create a Session for each one and have all your shells, consoles, logs, etc. available to switch to with a couple keystrokes.
  • Within a project you might be working on a significantly different branch. With Sessions it is easy to manage seperate installations of the same project by being able to jump back and forth between contexts.

OK, there's one other thing you really need to know before going too far. The environment for each Tmux entity you create will be determined by:

  • The Server will inherit the environment of the terminal it is stared in. Once started, the Server's environment can be modified.
  • A new Session will inherit the environment of the Server. Once created, the Session's environment can be modified.
  • A new Window will inherit the environment of the Session.
  • A new Pane will inherit the environment of the Window.

The power of the tool doesn't come for free; there can be annoyances. For example, if you have your web framework's dev server running in one session, you need to specify a different port if you want to start one in another session. A pitfall is that you can do things like creating a new window and being in an environment context you don't expect. (Show example)

Managing sessions, windows and projects

Setting Session environment variables

General Workflow Tips

Rename sessions

Rename windows

Recreating sessions / templates

##Using Tmux with Python virtualenv

Copy link

tjoels commented Feb 18, 2017

This is great! I am using Tmux, and this really caught my attention.
Seems like this gist is a work-in-progress - wouldn't mind reading the ending ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment