So what if you would like to record yourself every time you make a commit in git. That is possible with the lolcommits gem, a nice utility created by Matthew Rothenberg.

Image for post
Image for post

It’s just really cool 🤘 to see every commit linked with your current animated mood. But it can be a hassle to setup, especially when using external git GUI’s like Tower.

How to setup?

Before installing the lolcommits gem, we need to install some dependencies with Homebrew . Run the following command in your favorite CLI to install ImageMagick & FFmpeg:

brew install imagemagick ffmpeg

Now you are ready to install the `lolcommits` gem:

gem install lolcommits

Commit hook

Now let’s setup a commit hook for our project in git. But first let me explain to you what this does. A post-commit hook is a script that triggers after every commit (hence the name post). This way we can automate some post-commit actions.

In our case we want to run the lolcommits command with some options.

Add the following file to your git repository on this location .git/hooks/post-commitwith the content below:

#!/usr/bin/env bash# We only execute the script when not merging or rebasing.
if [ ! -d "$GIT_DIR/rebase-merge" ]; then
# Set the correct language.
export LANG="en_US.UTF-8"

# Add homebrew to the PATH.
export PATH="/usr/local/bin:$PATH"

# When using Rbenv we need to add the shims directory to the PATH.
export PATH="~/.rbenv/shims:$PATH"
# Define the directory where the gif will be placed.
export LOLCOMMITS_DIR=/Users/fousa/Dropbox/Lolcommits
# Generate the gif.
lolcommits --capture \
--animate=4 \
--delay=5 \
--device='FaceTime HD Camera' >/dev/null 2>&1 &
fi

Now you just have to make sure the post-hook is executable.

chmod +x .git/hooks/post-commit

A few extra words about the script:

  • You can fetch the device name by running lolcommits --devices in the command line. I prefer to use my MacBook’s camera.
  • We delay the execution of the script because the camera needs some time to start. Otherwise the gif has a black initial frame which is a bit fugly. 😣

More configuration options available here.

Existing projects

But what about existing projects? We’ll create a git template so you don’t always have to create the post commit hook.

Now let’s copy the post-commit hook here: ~/.git_template/hooks/post-commit. Next, set the template directory in your .gitconfig file like this:

[init]
templatedir = ~/.git_template

Then this hook will be automagically added to your project every time you run git init.

You can even just re-run git init in the root of your project. This will copy the post-commit configuration from the template to your repository. When a hook is already present, you’ll have to remove it to get it copied on git init. (or you can just add the required code to the post-commit script)

Automation is awesome! 🤘

Image for post
Image for post

Written by

iOS Developer Check out my Twitter app http://t.co/yTu9KBwFzs. Available in the Mac App Store. Look at my other apps at http://t.co/hEiWpPKvDd!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store