
Git + Twitter = Friedcode
22nd of April 2009
I've now written my first Git hook. For the people who don't know what Git is you have either lived under a rock for the past few years or your not into computer programming at all.
The hook is a post-commit hook and what it does is that it sends the last commit message up to a twitter account I called "friedcode". I guess it's not entirely useful but for you who want to be loud about your work and the progress you make I guess it can make sense. Or if you're a team and you want to get a brief overview of what your team mates are up to. For me, it was mostly an experiment to try Git hooks and pytwitter. Here's how I did it:
Go into the .git directory and edit the file 'post-commit':
$ cd .git/hooks
$ jed post-commit
Here's the script I wrote which contains some horrible python one-liners simply because my sed/awk-fu isn't good enough:
last_message=`git log --pretty=oneline -n1`
last_message=`echo $last_message | python -c "import sys;sys.stdout.write(\
' '.join(sys.stdin.read().strip().split()[1:]))"`
repo_name=`git info | head -n1`
repo_name=`echo $repo_name | python -c "import \
sys;sys.stdout.write(sys.stdin.read().strip().split('/')[-1])"`
echo "($repo_name) $last_message" | Update_friedcode.py
To enable the hook what you have to do is simply make it executable and you're done:
Then I needed the pytwitter script called Update_friedcode.py which I've put in '~/bin':
import sys
"""To use:
$ echo "I ate too much" | ./Update_friedcode.py
"""
U = 'friedcode'
P = <something something>
import pytwitter
client = pytwitter.pytwitter(username=U, password=P)
status_update = sys.stdin.read().strip()[:140]
client.statuses_update(status=status_update)
Comment
Show all 10 commentsCommenting is currently disabled in Mobile version