Thursday, July 21, 2011

Some quick functions from my .shrc_local

It's pretty well known that I have a fairly hefty .shrc which I created sometime ago to address the little things that bugged me when going from FreeBSD to say Linux or from OS X to maybe Cygwin ( ${deityOfYourChoice:="God"} help me ).  When I published it, I tried to make sure that it was both functional for the general public (ok.. admittedly a self-selecting sub-sub-sub culture of the general public) and generic enough to not get in the way of people who want to extend it for their specific needs.
Enter: .shrc_local. There are other places where one could make customizations and I actively encourage that, but if you just want something simple you can create a ~/.shrc_local and drop it in there.

Here is one example of that (pulled directly from my .shrc_local):

rvm(){
    #Quick wrapper function to make RVM (https://rvm.beginrescueend.com/) work
    #if you're using a sane shell instead of 'bash'. Bash still needs to be 
    #installed as RVM depends on it. This function simply wraps around bash
    #passing in the init script (~/.rvm/scripts/rvm) and the parameters so that
    #you aren't stuck when your default shell is something other than bash or 
    #zsh
    echo "
        source ${HOME}/.rvm/scripts/rvm 
        rvm $*
    " | bash
}


Here is another:

update_pkgsrc(){
    #Quick function to update my pkgsrc source tree.
    export CVSROOT=anoncvs@anoncvs.NetBSD.org:/cvsroot
    cd /usr/local/pkgsrc
    cvs update -A -Pd
}

I hope others will find these useful but if not.. at least I've posted them somewhere so that I can find them easily instead of searching through my tarsnap archives.. ;-)

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

create_session(){

    #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
            ./web2py.py --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.