Created
July 2, 2016 16:00
-
-
Save shofetim/59e1a450ec243d508a74dcaf51681b4a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
'use strict'; | |
/* | |
I am like git, except that I act on 'projecttown' repos that share a | |
directory with me, and I add an extra command, `recent` which | |
displays each repos branches, and last commit time for each branch. | |
*/ | |
var exec = require('child_process').execSync, | |
log = console.log.bind(console), | |
fs = require('fs'), | |
path = require('path'); | |
var getDirs = function(p) { | |
return fs.readdirSync(p).filter(function(file) { | |
return fs.statSync(path.join(p, file)).isDirectory(); | |
}); | |
}; | |
var reset = '\x1b[0m'; | |
var bright = '\x1b[1m'; | |
var dim = '\x1b[2m'; | |
var underscore = '\x1b[4m'; | |
var blink = '\x1b[5m'; | |
var reverse = '\x1b[7m'; | |
var hidden = '\x1b[8m'; | |
var fgblack = '\x1b[30m'; | |
var fgred = '\x1b[31m'; | |
var fggreen = '\x1b[32m'; | |
var fgyellow = '\x1b[33m'; | |
var fgblue = '\x1b[34m'; | |
var fgmagenta = '\x1b[35m'; | |
var fgcyan = '\x1b[36m'; | |
var fgWhite = '\x1b[37m'; | |
var announce = function (repo) { | |
log(bright, underscore, fgyellow, repo, reset); | |
log(' '); | |
}; | |
var git = function (repo, args) { | |
announce(repo); | |
log(exec('cd ' + repo + ' && git ' + args).toString()); | |
}; | |
var recent = function (repo) { | |
var cmd = 'git for-each-ref --sort=committerdate refs/remotes/ '; | |
cmd += '--format=\'%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - '; | |
cmd += '%(color:red)%(objectname:short)%(color:reset) - %(contents:subject)'; | |
cmd += ' - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))\''; | |
announce(repo); | |
log(exec('cd ' + repo + ' && ' + cmd).toString()); | |
}; | |
getDirs('./').filter(function (i) { | |
return (i.search('projecttowne') > -1); | |
}).forEach(function (repo) { | |
if (process.argv[2] == 'recent') { | |
recent(repo); | |
} else { | |
git(repo, process.argv.slice(2).join(' ')); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment