diff --git a/git-contributors b/git-contributors new file mode 100755 index 0000000..7a7f1be --- /dev/null +++ b/git-contributors @@ -0,0 +1,41 @@ +#!/usr/bin/env ruby + +def git_dir? + File.exists?('.git') || `git rev-parse --git-dir >/dev/null` +end + +def authors + `git log | grep '^Author:' | sed -e 's/Author: //g' | sort -f | uniq`.split(/\n/) +end + +def authors_by_field n + raise "invalid field #{n}, expected 0 or 1" unless n == 0 || n == 1 + other = (n-1).abs + authors.inject({}) do |as, a| + parts = a.split(' <') + parts[1].sub!(/>$/, '') + (as[parts[n]] ||= []) << parts[other] + as + end +end + +def authors_by_name; authors_by_field(0) end +def authors_by_email; authors_by_field(1) end + +def main + exit 1 unless git_dir? + + sort = :name + sort = ARGV.first.to_sym if ARGV.length > 0 + if sort == :name + authors_by_name.each do |name, emails| + puts "#{name} <#{emails.join(', ')}>" + end + else + authors_by_email.each do |email, names| + puts "#{email}: #{names.first} (aka #{names[1..-1].join(' aka ')})" + end + end +end + +main if $0 == __FILE__ diff --git a/progress b/progress new file mode 100755 index 0000000..849480c --- /dev/null +++ b/progress @@ -0,0 +1,47 @@ +#!/usr/bin/env ruby + +STDERR.sync = true + +$bytes = true +$max = nil +$count = 0 + +until ARGV.empty? + case (arg = ARGV.shift) + when '-l' + $bytes = false + when '-b' + $bytes = true + when /\A(\d+)([kmg]?)\Z/ + units = {'k'=>2**10, 'm'=>2**20, 'g'=>2**10, nil=>1} + $max = $1.to_i * units[$2] + else + raise "Unrecognized argument: `#{arg}'" + end +end + +$max = STDIN.stat.size if $bytes and STDIN.stat.file? and $max.nil? + +Thread.new{ + last_count = nil + while true + if $count != last_count + if $max + STDERR.print "\r#{$count}/#{$max} [#{$count*100/$max}%]" + else + STDERR.print "\r#{$count}" + end + last_count = $count + end + sleep 1 + end +} + +begin + while data = ($bytes ? STDIN.read(2**12) : STDIN.gets) + STDOUT.print(data) + $count += $bytes ? data.length : 1 + end + STDERR.print "\n" +rescue Errno::EPIPE +end