?

Log in

No account? Create an account
entries friends calendar profile Elf Sternberg's Pendorwright Projects Previous Previous Next Next
git wordcount - Elf M. Sternberg
elfs
elfs
git wordcount

This is an early draft, but I figured you might enjoy taking a look at my latest little toy:


#!/bin/bash

ARG=""

if [ "${1:0:2}" == '-h' ]; then
    HEAD="${1:1}"
    HEAD=${HEAD//h/^}
    ARG=" HEAD$HEAD..HEAD "
fi

REM=`git diff -U $ARG | grep '^-' | sed 's/^-//' | wc -w`
ADD=`git diff -U $ARG | grep '^+' | sed 's/^+//' | wc -w`
DIF=`expr $ADD - $REM`
echo "Word count: $DIF"

As I’m sure I’ve mentioned before, I write award-winning science fiction as well as hack code, and I use emacs for both activities. I’ve always written primarily in what I think of as Usenet mode, with asterisks and underscores for emphasis and bolding, respectively, a mode that has become codified as Markdown. I used to have my own homegrown toolkit for that, but these days I just use the Python version of Markdown instead. I’ve always used a VCS for that, living entirely in GIT almost since the beginning.


I wanted a simple script to tell me my daily progress. This is it. It compares what’s on the filesystem right now to the latest check-in, or, if you pass it the -h option, it will compare the last check-in to the previous check-in. Each additional -h will push the oldest comparison back one commit, so -hhh will compare the last check-in to the one three check-ins ago.


After writing this, I learned about git-sh-setup and --word-diff=porcelain, both of which will find their way into a future version; hopefully soon you’ll be able to say ‘git wc HEAD^^^..HEAD^^’ or similar, and see how productive you were any two days in the past.

Leave a comment