Playing (music) with git notes

Did you know that you can add notes to a git commit? Of course you do, because you’ve read Scott Chacon and Ben Straub book that tells you everything about git*. The cool thing about git notes is that they are not pushed with the commit (unless you actually want to) and that they can be “namespaced”. You’ll find everything you need about notes on this page.

Calvin Russell

Like a lot of people, I enjoy listening to music when my girlfriend is watching parenthood I work, usually with Spotify. Currently playing while I write this short post is Calvin Russell’s Petit gars. I know that because an AppleScript told me.

Now playing with AppleScript

I realized that I completely forgot to re-enable scrobbling to lastfm when I clean-installed Yosemite and it made me think of something. How about linking what I’m working on to what I’m listening to?

The first step you need to do is to store somewhere the following Applescript file (in my case, that’s ~/Scripts/Spotify-nowplaying.scpt):

tell application "Spotify"
	artist of current track & " - " & name of current track & " (" & spotify url of current track & ")"
end tell

Because I don’t like hardcoding anything, I’ve stored the fullpath to this script into a git configuration key, like this:

$ git config --global --add nowplaying.path "$HOME/Scripts/Spotify-nowplaying.scpt"

Finally, I’ve added the following lines into a git post-commit hook (don’t forget to chmod +x .git/hooks/post-commit or your hook won’t be invoked at all):

#!/bin/sh
path=$(git config nowplaying.path)
nowplaying=`osascript $path`
git notes --ref=nowplaying add -m ":musical_note: - $nowplaying"

Now, every time I’m committing something I’ll actually have a nice note showing information about the current track I was listening to.

Known issue: the script will fail if Spotify isn’t running.

Workaround: listen to music.

Git log with music

(* to be honest I’m not sure git notes are actually mentioned)