Last Updated: September 09, 2019
·
593
· gkalabin

Taking a photo every time you commit

I've liked idea in this tip. But that idea is only applicable for OSX. I have archlinux. So, I've done that on my archlinux.

What do you need to set this up:

  • bash
  • git 1.7.2+
  • fswebcam

Following script takes a photo and puts that in ~/.gitshots directory:

#!/bin/bash
DIRNAME=.gitshots
mkdir -p ~/${DIRNAME}
cd ~/${DIRNAME}
now=$(date +"%Y_%m_%d__%H_%M_%S")
filename="shot_${now}.png"
fswebcam -r 1280x720 -D 1 "${filename}"

You could save this script in ~/bin/photo-on-commit.sh

Then setup git hook in order to take photo (execute photo-on-commit.sh) every time you commit.

First of all create user-specific git template directory: mkdir -p ~/.git_templates/hooks and tell git about that: git config --global init.templatedir '~/.git_templates'

Now link our script into the hooks dir:

  • go to the filesystem root cd /
  • ln -s /home/your_name/bin/photo-on-commit.sh /home/your_name/.git_templates/hooks/post-commit-scripts

So, we've almost done. Add actual post-commit script to ~/.git-templates/hooks/:

#!/bin/bash
for file in .git/hooks/post-commit-scripts/*.sh
do
    exec $file >/dev/null 2>&1
done

This script will run all scripts in post-commit-scripts directory and redirect all their output to /dev/null. Don't miss to make all that code executable: # chmod +x post-commit for example.

All repos you will clone and init will use this post-commit hook. In order to add this hook to existing repos just reinit them (git init) - it's safe.