Last Updated: February 25, 2016
· ashleyblackmore

beardsnapper: take a picture upon git commit in linux

You can put the following into a bash script and run it, it should get you up and running.

You can clone the repository here:

Changes/suggestions are welcome!

# Idea taken from Víctor Martínez:
# Incorporates changes by iHiD (
# Find this script on github at
# Warning: this has only been tested on Ubuntu!

func_pause() {
    read -p "$*"

func_apt-get() {
    sudo apt-get install streamer

func_pacman() {
    pacman -S streamer

func_yum() {
    yum install streamer

func_up2date() {
    up2date --install streamer

haveProg() {
    [ -x "$(which $1)" ]

echo 'WARNING: This will append to the end of your post-commit file, if it already exists. Back out'
echo 'now if you do not want this to occur.'
echo 'If your camera resolution is not 1280x720, please change it in this script before continuing!'
echo 'Additionally, this script _may_ require sudo/root user privilege, in order to install streamer.'
func_pause 'Press [Enter] key to continue...'

if haveProg apt-get ; then func_apt-get
elif haveProg pacman ; then func_pacman
elif haveProg yum ; then func_yum
elif haveProg up2date ; then func_up2date
    echo 'No package manager found. Please install streamer before executing this script again.'

mkdir -p ~/.git_templates/hooks
touch $bsnap

echo -e '#!/bin/bash' > $bsnap
echo -e 'forked_image () {' >> $bsnap
echo -e '    mkdir -p ~/Pictures/beardsnaps' >> $bsnap
echo -e '    streamer -q -s 1280x720 -c /dev/video0 -b 16 -o ~/Pictures/beardsnaps/$(date +%s)_$(basename $PWD).jpeg &' >> $bsnap
echo -e '}' >> $bsnap
echo -e '' >> $bsnap
echo -e 'forked_image &' >> $bsnap

chmod +x $bsnap

git config --global init.templatedir '~/.git_templates'