Bash Scripts for the Masses! (CVS Helpers)

I decided that I’d share a few little functions in my .bashrc that have been making my life nicer lately. (Yeah, nothing much to blog about. Or rather, I don’t feel like writing anything creative, because my brain is fried from lots of work and being away from home.)

Since we’re in the beginning stages of a project right now, everything is working out of HEAD in the CVS tree. It’s in maintenance modes when you really need to worry about a lot of tagging and branching and whatnot. So, I’ve been finding that it’s easiest to just use the command-line CVS client. Also, I’ve been up in Sunnyvale, working long hours on my laptop in a hotel room. VPN is a lot of things, but it ain’t quick, so my NFS mount has been pretty much worthless most of the time.

So, I wrote a few bash shortcuts so that I can quickly copy *just* my changed files over to my FreeBSD box.

This one copies all the changed files (according to CVS) in the current folder over to the corresponding folder on my FreeBSD box. Replace “DevBox2″ with your local sandbox, and the tillnearly…/isaacs/dev/ with the corresponding servername and folder on the server. It won’t copy conflicts.

copychanges () {
  if [ "$target" == "$target0" ]; then
    echo “not in code folder!”
  echo “copying changes in $target to${target}/”
  for i in `cvs update -dP | egrep “^[ABD-Z] “`; do
    if [ -f "$i" ]; then
      # get the path from here to there..
      pathToFile=`dirname $i`
      scp $i${target}/$pathToFile/

Forgetting to put in the dirname call almost led to me crashing my box by building up a 3,857,666,294 byte apache error log. *^_^*

This one is for clearing conflicts. Set up edit to be an alias for your favorite text editor. (Old-schoolers can put alias edit=`which vi` in their profiles. Mine is alias edit="open -a 'TextMate' ".) It walks through each conflict.

clearconflicts () {
  for i in `cvs update -dP | egrep "^C "`; do
    if [ -f "$i" ]; then
      echo -n “$i - what to do? (C)lean copy, (E)dit, (S)kip (skip) ”
      read -n 1 action
      if [ "$action" == "C" ] || [ "$action" == "c" ]; then
        cvs update -C $i
      elif [ "$action" == "E" ] || [ "$action" == "e" ]; then
      edit=”$edit $i”
  for i in “$edit”; do
    if [ -f "$i" ]; then
      edit $i

Last but not least, a one-liner that just shows you the files that matter, and skips all the ? files that I seem to accumulate in my CVS sandboxes. (”ug” stands for “update and grep”. Is it really any more poorly named than ls or chmod?)

alias ug='cvs update -dP | egrep "^[^\?]“‘

4 Responses to “Bash Scripts for the Masses! (CVS Helpers)”

  1. On May 10th, 2007 at 16:33:50, SeventhCycle Said:

    A 3,857,666,294 byte error log? Ouch! I remember about 4 years back running a website with a 2 gig access log. It slowed apache’s performance down to a crawl. That’s when I learned about the joys and necessity of log rotation. Gotta love apache admin stuff.

    So, any reason for a CVS preference over SVN?

  2. On May 10th, 2007 at 17:38:00, Isaac Said:

    I’ve heard good things about SVN. However, My Employer uses CVS, so that pretty much means that I use CVS :)

  3. On May 11th, 2007 at 09:41:22, geoffalot Said:

    SVN is good, but I can understand why an organization as large as Y! would have a hard time justifying a massive change for something that’s much more similar than it is different.

    Do you prefer not to use Vim or emacs? It seems like you could avoid all the NFS and VPN performance / configuration shenanigans by just connecting straight to the dev box via ssh, then looking at the results via a tunnel.

  4. On May 11th, 2007 at 09:54:05, Isaac Said:

    True that. OTOH, there have been a lot of cases where even logging in to restart apache is painful. With all the advances in high-speed internet and network tunneling, we’ve managed to reproduce the user experience of a 9400 bps modem. It’s rough when you can type significantly faster than the display can update.

    And, I’m addicted to TextPad’s lovely keyboard shortcuts, and customizable syntax highlighting. I’m working on figuring out how to put my dev box in a Parallels VM so that networking won’t even be an issue.

Leave a Reply

Comments are moderated like crazy using a variety of plugins. There is a very high likelihood that your comment won't show up right away, especially if you have never commented here before, but it was not deleted.

Please be patient, and do not post your comment more than once. It will show up once it is approved.

You must be logged in to post a comment.