Skip to content

Instantly share code, notes, and snippets.

@lucaong
Created May 14, 2013 12:30
Show Gist options
  • Save lucaong/5575541 to your computer and use it in GitHub Desktop.
Save lucaong/5575541 to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
require 'date'
require 'fileutils'
require 'optparse'
def parse_cli_options
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: git standup [--since=<date>] [--author=<name>]"
opts.on("--since[=OPTIONAL]", "Show commits more recent that a specific date (defaults to a weekend-aware guess of last working day)") do |since|
options[:since] = since
end
opts.on("--author[=OPTIONAL]", "Show only commits from a particular author (defaults to the user defined in .gitconfig)") do |author|
options[:author] = author
end
end.parse!
options
end
def output_log(options={})
# TODO (2013-05-13) Branch info would be nice
log_format = '%Cred%h%Creset -%Creset %s%Creset'
author = options[:author] || %x[git config user.email].strip
today = Time.now.to_date
week_day = Date::DAYNAMES[today.wday]
if week_day == 'Monday'
last_working_day = today - 3
else
last_working_day = today - 1
end
%x<git log --pretty=format:"#{log_format}" --since="#{options[:since] || last_working_day.to_s}" --author="#{author}">
end
options = parse_cli_options
if File.directory?('.git')
puts output_log(options)
end
Dir['*/.git'].each do |git_dir|
project_dir = File.dirname(git_dir)
project_log = nil
FileUtils.cd(project_dir) do
project_log = output_log(options).strip
end
if project_log != ''
puts ">> Project: #{project_dir}"
puts project_log
puts
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment