Saturday, July 9, 2011

tmux is awesome: how I use it for development with web2py

Thank goodness for BSD hackers. GNU Screen is a very nice piece of software. Tmux, however, is flippin awesome. The simple concept of Windows with Panes is enough to make me forever discontent with the any other terminal multiplexer. It's a useful feature and one that I employ in many of my scripts.

The above is an example of a multi-pane window. It's the result of the following script that I use when I do development in web2py. The left side can be used to track down debugging messages or even open a vi/vim session. The upper right pane is where my web2py server is running and I can pop in to restart it as needed. The middle and bottom right panes are used for making (frequent) commits my version control system of choice (fossil) and running tests (web2py makes it really easy to run tests from the command line). 

TMUX Script: 

#! /bin/sh


    #get to our main directory
    cd ~/prog/web2py/generic

    #Create new empty session (detached)
    tmux new-session -d -s ${1}

    #Split first window (vertically
    tmux split-window -h  -t ${1}:0  '{
        while [ "${restart_answer:-yes}" != "no" ]; do
            ./ --no-cron -a "admin"
            echo ""
            echo "Press ENTER to restart web2py"
            echo "Enter \"no\" to quit"
            read restart_answer
        done ;}'
    cd /Users/gcw/prog/web2py/generic/applications
    tmux split-window -v -t ${1}:0 -p 65
    tmux split-window -v -t ${1}:0 -p 50
    tmux select-pane -t ${1}:0

create_session web2py-generic

Everything get's started up in up in detatched mode which means that when I want to connect to it I just run 'tmux attach -t web2py-generic and I'm in.

No comments:

Post a Comment