Skip to content

Instantly share code, notes, and snippets.

@robskillington
Created September 19, 2014 16:16
Show Gist options
  • Save robskillington/776e6a7e34863848ede8 to your computer and use it in GitHub Desktop.
Save robskillington/776e6a7e34863848ede8 to your computer and use it in GitHub Desktop.
numstatall - pipe the output of `git diff --numstat <commit-ish>` to get total add and deletions
#!/usr/bin/env coffee
readline = require 'readline'
rl = readline.createInterface
input: process.stdin
terminal: false
stat = {add: 0, del: 0}
rl.on 'line', (line)->
diff = line.split '\t'
if diff.length == 3
add = parseInt diff[0]
del = parseInt diff[1]
if !isNaN(add) && !isNaN(del)
stat.add += add
stat.del += del
format = (num)->
num.toString().replace /(\d)(?=(\d{3})+(?!\d))/g, "$1,"
rl.on 'close', ()->
console.log "total add: #{format(stat.add)} del: #{format(stat.del)}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment