Monday, July 1, 2013

tmux

I have used screen for a long time. I recommend it to anyone who is unlucky enough to say something about terminals, ssh, or session disconnects anywhere near me. I’ve never been a screen power user though. I’ve always just got by with the basics for a single use case and haven’t had enough reason to invest in learning any more. I know this isn’t all screen can do, but in my mind, screen was always the thing I ran right away once I ssh’d into another box. Over the last few years, the number of places I kept a screen session waiting for me has dwindled down to a couple. It’s the same use case, a headless Linux box that has a long running screen session. I don’t think I’ve even used more than one window in screen in three years. It provides me with a saved state and I don’t have to think whether I’m running something in the ssh session before I close my laptop.


At my current job, when I run our product in my dev environment, I start three processes at the cmdline. I want all those cmdlines. I want their log output. I want to kill and restart them at particular times. This morning, I got fed up with trying to find a layout of terminal windows or tabs that I liked so I thought I would finally go learn more about screen to see if the solution had been under my nose all the time.


A quick bit of searching led me to to try tmux. It’s new (to me) and shiny and apparently I was looking for a distraction. A few minutes later, I had read a few tips and tricks posts  and had the following setup working.




My ~/.tmux.conf is in the upper left pane. For my debug cycle, the best thing about this is the line ‘bind = setw synchronize-panes’. With that, ‘Ctrl-b =’ toggles synchronized input for all panes. When this is toggled on, Ctrl-C breaks all three processes. Then ‘up-arrow’ followed by ‘enter’ gives me the last command ran in each pane and runs it. Simple. If I want to do more work in a single pane, I just toggle it off and ‘Ctrl-B o’ my way to that pane.


Like screen, If I accidently close the terminal window, the processes don’t die. If I intentionally stop the application processes and close the terminal window to get it out of my way on a Friday and for some reason don’t work again until Monday, I keep all my state, pane layout, etc just by doing ‘tmux attach’. My personal laptop is my main desktop computer and my work development computer. It seems like tmux and a BYOD [LINK: ]  laptop were made for each other.


It’ll take awhile to get the common keyboard shortcuts into muscle memory, but tmux has demonstrated enough value in such a short time that I know I’m going to take the time. I’m a fan.

No comments: