Roger Steve Ruiz is a software engineer.
Reading time: 6 mins

Setting up lolcommits

Written on 28 May 2016 (Link to this post)
automation devex git mac

Setting up lolcommits for local selfies from Git commits you make on your machine using your camera. This is geared towards Mac OS X users.

Table of contents

tl;dr

To get the most from this post, you’re gonna need to really read through it. But, basically I walk you through how to setup lolcommits up for yourself locally and automatically post captures to Tumblr.

➡️ Check out my rogerisworking Tumblr

Check out the latest source for post-commit script

Getting started

This guide makes some assumptions that you’re using the terminal to run the following commands, and that you’re using Mac hardware and software.

Installing lolcommits is pretty easy via Ruby Gems. If you’ve got the gem command on your computer, you can simply run the following command.

Installing lolcommits
gem install lolcommits
# If you've got permission errors, `sudo` like you mean it ( ie: `sudo !!` )

After it installs, you can make sure it’s available by running lolcommits.

Running lolcommits
lolcommits

Do what exactly?
Try: lolcommits --enable   (when in a git repository)
Or:  lolcommits --help

Great. Now that the binary is installed and in your $PATH, we can focus on customizing it. I personally use it to post everything I commit as a photo to a Tumblr I made specifically to cope with the dehumanizing aspects of working with computers .

Feel free to skip around to any of the following sections.

Initializing teh lulz

To get started you can run lolcommits --enable within any git repository you’d like. This does a few things which are pretty destructive if you use the post-commit hook. So make sure you back it up.

Backing up the post-commit file
cp .git/hooks/post-commit .git/hooks/post-commit.bak

Now you can safely run lolcommits --enable.

Enabling lolcommits locally
lolcommits --enable

installed lolcommit hook to:
  -> $HOME/Developer/<REPO>/.git/hooks/post-commit
(to remove later, you can use: lolcommits --disable)

Which will give you the following output inside of .git/hooks/post-commit.

.git/hooks/post-commit
cat .git/hooks/post-commit

#!/bin/sh
### lolcommits hook (begin) ###
if [ ! -d "$GIT_DIR/rebase-merge" ]; then
export LANG="en_US.UTF-8"
export PATH="$HOME/.rvm/rubies/ruby-2.2.2/bin:/usr/local/bin:$PATH"
lolcommits --capture
fi
###  lolcommits hook (end)  ###

Customizing teh lulz

Now that we’ve got the hook installed, you can make your first commit and see what it’s all about. You’ll notice on the post-commit file that line 6 is just a call to lolcommits --capture. This is what takes the commit image. It accepts some additional flags to customize your experience. Feel free to play around with them.

Getting help with lolcommits
lolcommits --help

Usage: lolcommits [-vedclbscpsmwga]
    # shortened for emphasis & brevity
    -c, --capture                    capture lolcommit based on last git commit
    -w, --delay=SECONDS              delay taking of the snapshot by n seconds
        --stealth                    capture image in stealth mode
    -a, --animate=SECONDS            enable animated gif captures with duration (seconds)
        --fork                       fork the lolcommits run

Once you run the --capture command within a repo with commits, you can see your lolcommit image by running lolcommits --browse. This will open the Finder.app to the folder containing all the lulz. It’s useful to keep this open as you tweak your lolcommits --capture ** command so you can preview your changes.

Here’s the command I use to capture my lovely commits:

Flags I use to capture
lolcommits --capture --fork --stealth --delay=3 --animate=5

I find that --fork allows me to quickly capture commits. The --stealth flag helps me forget it’s taking a picture, even though the green light will still turn on. The --delay=3 is great so that the iSight camera can focus on you. Finally, --animate=5 is what gives me *.gif files that I can later upload to Tumblr. This means I don’t get any *.jpg files. I personally don’t mind losing them, but if you want you can always run the command twice once without the --animate=* flag.

Configuring teh lulz

There are quite a few plugins available for lolcommits that do all sorts of fancy things. The one I like to use is the Tumblr plugin, since I don’t want to worry about hosting or theming of my lolcommits.

To configure Tumblr, you just need to follow the prompts after running the configuration command.

Configuring Tumblr
lolcommits --config -p tumblr

Each prompt will walk you through the steps needed to enable the Tumblr configuration. Once you’ve successfully configured the plugin, lolcommits will generate a config.yml file for you in the $HOME/.lolcommits/<REPO_NAME>/ directory. This config.yml is what tells lolcommits what configurations to use after it creates an image. You can take a look at the source for the Tumblr plugin here .

Viewing the config file
cat $HOME/.lolcommits/`echo ${PWD##*/}`/config.yml

---
tumblr:
  enabled: true
  access_token: <REDACTED_SECRET>
  secret: <REDACTED_SECRET>
  tumblr_name: rogerisworking

Automating teh lulz

Once you’ve gotten a single repository enabled and tweaked to your liking, you might want to ensure that all of your newly cloned repositories and old repositories are using lolcommits to capture your beautiful selfie. This can be very time consuming as you’d need to run lolcommits --enable within each repository and then copy over the config.yml file into that new folder within $HOME/.lolcommits. Or you could automate it.

Now, this has less to do with lolcommits and more to do with git itself. Git’s init function, which is called on git clone and git init within a directory, supports a template directory . This directory can be anywhere in your system and referenced within your global Git configuration file ( ie ~/.gitconfig ).

Setting up your ~/.git_templates/ directory

To setup your git_templates/ directory, you can follow these commands:

Creating a Git template directory
mkdir -p $HOME/.git_template/hooks/ && \
git config --global init.templatedir ~/.git_template

Once you’ve configured git to recognize the $HOME/.git_template directory as your git init template directory, you can copy the post-commit file that lolcommits generated in the repository you ran lolcommits --enable and tweaked to your liking above.

Copying the post-commit file to templates
cp -v .git/hooks/post-commit $HOME/.git_template/hooks/post-commit

This will insure that git init and git clone copies over the post-commit file into the repositories .git/hooks/ directory. Now every repository you clone or create on your machine will have lolcommits enabled by default.

Fun Fact: This is a feature of git and not lolcommits so you can use it for any other git-hook templates you’d like to copy over into new repositories.

Synchronizing your config.yml files

Once you’ve created a config.yml file that automatically uploads things to Tumblr, you need to make sure to copy that file over to each directory within $HOME/.lolcommits/. I keep my base config.yml at the root-level of the $HOME/.lolcommits/ directory and copy it over using the following command whenever I’m working with a new repository on my machines.

Copying the config file
cp -v $HOME/.lolcommits/config.yml $HOME/.lolcommits/`echo "${PWD##*/}"`/config.yml

This post was written by a human & not by artificial intelligence (AI) tools. I don't have anything against AI but I am interested in differenciating content created by people versus machines. To find out more about the Not by AI badge, please click it.


If you enjoyed this post, please explore other posts by the topics listed below.

automation devex git mac
Previous Post Smooth terminal