developing with tmux

Sat, Jan 25, 2014

Many years I used to work almost exclusively in two development environments. Visual Studio and SoftICE, the latter making me a bit of a digital hermit which I wrote about a few years ago. Back then I’d realised the eremitic connotations of software development and they’ve hovered like a presence in the background throughout my softare development career.

Since leaving the driver days behind, that hermit’s cave of SoftICE has been replaced, in turn, by multiple Windows command prompt windows all crammed into a tiny monitor, fighting for space not only on the screen but in my brain’s limited short term memory banks. Where’s the apache window? I need those applicationg logs, now where did I put them?

Moving on, the monitor has become much much bigger and had an even bigger one planted next to it. The smaller has housed the IDE while the larger has a plethora of OS X terminal windows open. With the same problem as before. Where is that log window?

Then came iTerm2 and its tabs and its scripting capabilities. Getting fed up opening tabs and navigating to various development directories I knocked up a script to do it all for me:

tell application "iTerm"
  set myterm to (make new terminal)
    tell myterm
     set number of columns to 160
     set number of rows to 32

     set toolkit_git_session to (make new session at the end of sessions)
     tell toolkit_git_session
       set name to "ltk-ui-git"
       exec command "/bin/bash --login"
       write text "cd dev/LEARN/ltk-ui;rvm use 1.9.3@ltk-fedora-rest;git status"
     end tell
  end tell
end tell

However, the problem remained. Where is the tomcat tab?

Plus the constant context switching of moving from compiling to fumbling for the mouse, to clicking tabs until I found the right one, to typing commands, to more fumbling to find the right tab again degraded the whole development process.

And then I heard about tmux, a ‘terminal multiplexor’. Lots of people were raving about it and I was a little sceptical of the claims. After all, it’s just a fancy terminal. Plus I was used to the mouse by now, even if it was chipping away at my concentration, stealing cycles, leaking memory. But downloaded it, read a really good book on it and knuckled down to some scripting.

tmux has-session -t MatrixBlackboardPanel
if [ $? != 0 ]

tmux new-session -s MatrixBlackboardPanel -n matrix-blackboard-panel -d

tmux send-keys -t MatrixBlackboardPanel 'cd dev/matrix/matrix-blackboard-panel' C-m
tmux send-keys -t MatrixBlackboardPanel 'clear' C-m
tmux send-keys -t MatrixBlackboardPanel 'git status' C-m

tmux new-window -n git -t MatrixBlackboardPanel
tmux send-keys -t MatrixBlackboardPanel:2 'cd dev/matrix/matrix-blackboard-panel' C-m
tmux send-keys -t MatrixBlackboardPanel:2 'clear' C-m
tmux send-keys -t MatrixBlackboardPanel:2 'git status' C-m

tmux new-window -n matrix-blackboard-panel-config -t MatrixBlackboardPanel
tmux send-keys -t MatrixBlackboardPanel:3 'cd /Volumes/CONFIGLOCAL/dev-config/matrix/matrix-blackboard-panel-config' C-m
tmux send-keys -t MatrixBlackboardPanel:3 'clear' C-m
tmux send-keys -t MatrixBlackboardPanel:3 'git status' C-m

tmux new-window -n local -t MatrixBlackboardPanel
tmux send-keys -t MatrixBlackboardPanel:4 'cd /Volumes/CONFIGLOCAL/dev-local/matrix/matrix-blackboard-panel-local' C-m

tmux new-window -n app-config -t MatrixBlackboardPanel
tmux send-keys -t MatrixBlackboardPanel:5 'cd /Volumes/APPSDEV/matrix-blackboard-panel/config' C-m

tmux new-window -n tomcat -t MatrixBlackboardPanel
tmux send-keys -t MatrixBlackboardPanel:6 'cd /Users/alistair/apps/apache-tomcat-6.0.28/logs' C-m
tmux send-keys -t MatrixBlackboardPanel:6 '../bin/ jpda start'

tmux new-window -n backbone -t MatrixBlackboardPanel
tmux send-keys -t MatrixBlackboardPanel:7 'cd dev/matrix/matrix-blackboard-panel/src/main/webapp' C-m
tmux send-keys -t MatrixBlackboardPanel:7 '/Applications/Sublime\ Text\ .'

tmux select-window -t MatrixBlackboardPanel:1


tmux attach -t MatrixBlackboardPanel

The above script create a tmux session called MatrixBlackboardPanel. It’s a project I’m working on to develop a client side single page application to talk the to Blackboard building block I developed for provisioning the VLE. You just create windows, send commands to them and eveything’s set up in an instant. I have another script that splits windows into panes for another project but this is nice and simple. Another feature I’m planning to try out is remote sessions. I can leave a tmux session running on my big Mac in the office and connect to it from home. Groovy!

So now my development environment looks like this:


I still have IDEs open outside tmux as I haven’t quite adopted the vi school of development. So I have Java code open in IntelliJ IDEA and Javascript open in SublimeText2 but the commands to open the SP2 project are ready and waitinf for me to hit return when the session starts.

Has tmux really boosted my productivity? I’d say yes. I’d also say in a pretty big way. I’ve rempped the command PREFIX to CTRL-A and moving from window to window is a breeze:

PREFIX 1 to move to the mvn window. Build and deploy. PREFIX 5 to move to the tomcat window. Start it up and tail the logs. CMD TAB to Chrome, Refresh. Not a mouse in sight. If I’ve forgotten a window number it’s just a case of hitting PREFIX w to see the list but the most used ones are stored in my register memory.

The memory hogging visual patterns of tab navigation by mouse have been optimised down to single key instructions capable of being stored in registers, leaving real memory free for developing.

Eremitic software development is alive and well. I just have to remember to go for a walk now and then to stretch the old legs. Get out of the digital hermit’s cave for nice fresh air.

comments powered by Disqus