Tmux Goodness

Many people are no doubt familiar with tmux. I was a long time user of gnu-screen, but I have since migrated to tmux, largely due to this post.

Up until recently, I hadn't explored any of the more advanced features, until on a whim I decided to look into sharing windows between sessions. In tmux vernacular, this is called linking, or more specifically link-window and unlink-window. This is, indeed, sweet as heck.

Tmux has this concept of windows. A window is basically whatever your looking at. And like the windows you have in your house (not the Microsoft variety), each window can be split up into several panes. This is different from the screen model of window splitting, because you stick two windows on the same screen. With tmux you have two panes in the same window. You can open, close, and re-arrange the panes how you will, but you can't have more than one window "open" (active?) at a time.

However, what you can do, is break and join panes with breakp and joinp.

Here's an example. I've got one window open right now, with two panes - one is editing this post, and the other is just a command line. When I do ^a-! (I've remapped C-b to C-a. I did come from screen, after all), I've got a new window with only one pane. :breakp (on the tmux command line) would've worked too. Or :break-pane. Now if I want to recombine these two windows into one (with index 1) I'll do ^a-^a, ^:joinp -s 2. Now the pane that was previously on the top is now on the bottom. Now I did ^a-{ to swap the panes, and voila! I'm back where I was.

Sweet as heck.

So what about them windows?

Well, let's say you create two tmux sessions, work and play. Inside play you've got an irssi client happily buzzing away while you're at work. But suddenly, you need to go visit #python on freenode to figure out why in the world you're getting a UnicodeError from this block of code. You can do :linkw -s work:irssi, and bam! Now you're looking at irssi inside your work session. Go ahead and ask your question, then you can simply :unlink-window and you're no longer looking at that window.

Of course, let's alter the scenario a bit - you don't get the answer before you go on your lunch break, so you detach from work and start to play instead (maybe catch up on blog posts through newsbeuter, or muck around on a MUD). Your irssi window will still be here. Both sessions are attached to the window.

You can also link panes that way, though you'll steal the window from the other session. However, you can send it back (if it wasn't the last window in that session!) by breaking the pane, then doing :linkw -t work, then :unlink-window.

You can combine linking/unlinking windows and breaking/joining panes in all sorts of fun and exiting workflows. I'm experimenting now with having an all session that contains all of my windows, and distinct sessions for programming, blogging, and system work. (^a-s I suspect will become another valuable command for me)