o12usw
3.262K
· June 2013 ·
43a40166b5d9fb6828e6c4214e3ba87d

TIP: How to Play a Sound Whenever You Commit to Git

One day it dawned on me: writing code alone at home can be a very isolating experience. There you are, day in day out, quietly making magic with your mind (sarcasm, obv.) only to silently commit the fruits of your labor into the void of your source control repository, appreciated by no one. If only a crowd of children could be retained for the sole purpose of cheering you on every time you complete something.

Amazingly, Brandon Keepers over at Collective Idea had the same exact same thought (almost; he was substantially less melodramatic in his blog post about it). Anyway, here is what my version of his script looks like:

#!/bin/sh

toplevel_path=`git rev-parse --show-toplevel`
afplay -v 0.1 $toplevel_path/.git/hooks/happykids.wav > /dev/null 2>&1 &

I put this in a file called .git/hooks/post-commit.playsound. I then trigger this from the main .git/hooks/post-commitscript as follows:

#!/bin/sh

toplevel_path=`git rev-parse --show-toplevel`
$toplevel_path/.git/hooks/post-commit.tweet
$toplevel_path/.git/hooks/post-commit.playsound

Where the post-commit.tweet script is the script from this blog post. If you aren't also tweeting your commit posts, you'll want to delete that line.

If you want this to work for every single Git repository from now on, add these scripts to your git-core templates. You’ll have to figure out where these are (it’s different for every setup). For my Mac, they’re located here: /opt/local/share/git-core/templates/hooks/post-commit.

–David

The post TIP: How to Play a Sound Whenever You Commit to Git appeared first on Adorno Media.

Sign in or sign up to add your response.

6 Responses

7220
38b86511b7a732db7a89d971c14c4aa0

cool!!!

over 1 year ago ·
7276
4f776ee53d980b0c7eac4814b7d327bf

Great post! I done something similar, but I wanted it to work through SSH – so it would still play the sounds even if I was working within a Putty session.

You've motivated to put mine up, haha – https://github.com/Matt-Stevens/Git-Banshee

over 1 year ago ·
7283
Cabd6b9f0380530c18ca13469eb39eae

Great protip! Are we allowed to play jingle bells each time?

over 1 year ago ·
7305
43a40166b5d9fb6828e6c4214e3ba87d

@matt-stevens: That's really cool. I like that it works even if you're in an SSH session.

over 1 year ago ·
7306
43a40166b5d9fb6828e6c4214e3ba87d

@jasdeepkhalsa: Yes, but only if you don't share an office with anyone else. ;)

over 1 year ago ·
7525
Lucas

I have this on my work machine playing the Mario coin sound. Love it.

over 1 year ago ·