Skip to content

Instantly share code, notes, and snippets.

@ruzz311
Forked from joelongstreet/BeautifulFaces.js
Last active December 14, 2015 07:39
Show Gist options
  • Save ruzz311/5052261 to your computer and use it in GitHub Desktop.
Save ruzz311/5052261 to your computer and use it in GitHub Desktop.
BeautifulFaces.js (for NVM users) Dependencies: imagesnap (http://iharder.sourceforge.net/current/macosx/imagesnap/) Description: Save this script as a post-commit hook to snap a photo of yourself and save it with your commit message
#!/usr/bin/env node
//
// BeautifulFaces.js
// https://gist.github.com/joelongstreet/5052198
//
// Dependencies:
// imagesnap (npm install -g imagesnap)
// Description:
// Save this script as a post-commit hook to snap a photo of yourself and
// save it with your commit message
//
var fs = require('fs');
var path = require('path');
// if nvm is installed
var globalModules = (process.env['NVM_BIN']) ? path.join(process.env['NVM_BIN'], '../lib/node_modules/') : ''
var imagesnap = require(globalModules+'imagesnap');
var picsPath = process.env['HOME'] + '/.gitshots/';
var commitPath = picsPath + new Date().getTime();
fs.mkdirParent = function(dirPath, mode, callback) {
fs.mkdir(dirPath, mode, function(error) {
if (error && error.errno === 34) {
fs.mkdirParent(path.dirname(dirPath), mode, callback);
fs.mkdirParent(dirPath, mode, callback);
}
callback && callback(error);
});
};
fs.mkdirParent(commitPath, 0777, function(){
var imageStream = fs.createWriteStream(commitPath + '/capture.jpg')
var messagePath = __dirname.replace('hooks', '');
fs.readFile(messagePath + 'COMMIT_EDITMSG', 'utf8', function(err, data){
fs.writeFile(commitPath + '/message.txt', data, function(err){
if(err) { console.log(err); }
});
imagesnap().pipe(imageStream);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment