Sometimes it takes quite an effort to be a “lazy programmer” (as in Larry Wall’s virtues of a programmer). I’ve been trying to optimize my workflow as I run into things that make for repetitive typing. I find when I can type less, I have more cycles to think. One of my favorite tools in laziness is bash scripting, but I’m still learning its ins and outs.

The problem: Lately I’ve been switching between subversion trees in OpenLaszlo. (Someday I want to convince the team to switch to git, but I’m not sure that would even solve the problem completely, since I also like having multiple webapps installed.) So I’ve got trunk checked out in different directories: a clean one for testing, one I keep for code reviews, a sandbox for whatever I’m working on at the moment, etc. Every time I switch OpenLaszlo contexts, I need to redefine $LPS_HOME environment variable and cd into that directory. Should be simple, huh?

BRANCH="trunk"
[ -n "$1" ] && BRANCH="$BRANCH-$1"

echo "BRANCH=$BRANCH"

export LPS_HOME=/Users/sarah/src/svn/openlaszlo/$BRANCH
cd "/Users/sarah/src/svn/openlaszlo/$BRANCH"
pwd

Except this didn’t work. It seemed that ‘cd’ had no effect and $LPS_HOME wasn’t modified. WTF? Lacking someone to look over my shoulder in my new solo work situation, I emailed my friend Scott Evans from whom I have learned much bash lore. He emailed me the following:

1) use “.” to run the script, which runs it in your shell process instead
of in a child one.

2) use a bash function instead — these run in your current environment.
try something like this in your bashrc/bash_profile:

trunk() {
 echo "dollar 1: ${1}"
 if [ -n "${1}" ] ; then
   export LPS_HOME=/Users/sarah/src/svn/openlaszlo/trunk-${1}
 else 
   export LPS_HOME=/Users/sarah/src/svn/openlaszlo/trunk
 fi

 cd $LPS_HOME
 pwd
}

Note that I didn’t set something like $TRUNK there — since the thing is running in your shell environment, it’s good practice not to potentially step on existing variables, or leave any variables defined after the fact.

Thanks Scott! Posting here so that I will always remember what I learned today and maybe some other folk will find it helpful.

Using git (and witnessing other people’s use of it through github’s social coding) has led me to have a different perspective on forking.  I overheard someone say at GoGaRuCo that “fork is the new friend.” When you fork someone’s code you are saying that you admire what that have done, that you like it enough to invest time in it.  You modify something, add a feature or fix a bug, then send a “pull request.”  This is typically the beginning of a collaboration.

I’ve been thinking about this after reading a conversation on the RailsBridge list last week about whether the groups was “forking” the Rails community and negative perceptions by some and fears of divisiveness.  I prefer thinking about it as a way to invigorate a part of the Rails community.

“Forking something doesn’t have to be negative and divisive – it can actually be positive and beneficial, generating new ideas and interest.” 

“We’re  creating a fork in order to develop and submit patches back, but with
community models instead of code.”

via RailsBridge discussion

Barack Obama’s speech at the White House Correspondents’ Dinner was entertaining and included some poignant notes on the challenges to journalism today.

Highlights on what he plans to accomplish in the next hundred days:

“During the second hundred days, we will design, build and open a library dedicated to my first hundred days”

“In the next hundred days, I will strongly consider losing my cool”

“Finally, I believe that my next hundred days will be so successful I will be able to complete them in 72 days. And on the 73rd day, I will rest.”

And on the serious side:

“I want to end by saying a few words about the men and women in this room whose job it is to inform the public and pursue the truth. We meet tonight a moment extraordinary challenge for this nation and for the world, but it is also a time of real hardship for the field of journalism. Like so many other businesses in this global age you’ve seen sweeping changes in technology and communications that lead to a sense of uncertainty and anxiety about what the future will hold… I know that each newspaper and media outlet is wrestling with how to respond to these changes and some are struggling simply to stay open and it won’t be easy. Not every ending will be a happy one. But it is also true that your ultimate success as an industry is essential to the success of our democracy. It is what makes this thing work.

“Thomas Jefferson once said that if he has a choice between a government without newspapers or newspapers without a government, he would not hesitate to choose the latter. Clearly, he did not have cable news to contend with, but his central point remains. A government without newspapers, a government without a tough and vibrant media of all sorts is not an option for the United States of America.

“I may not agree with every with everything you write or report, I may even complain… but I do so with the knowledge that when you are at your best, then you help me be at my best. You help all of us, who serve at the pleasure of the American people, do our jobs better, by holding us accountable, by demanding honesty, by preventing us from taking shortcuts and falling into easy political games that people are so desperately weary of. That kind of reporting is worth preserving, not just for your sake, but for the public’s. We count on you to help us make sense of a complex world and tell the stories of our lives the way they happen. We look to you for truth, even if it is always an approximation…”