Skip to content

Instantly share code, notes, and snippets.

@nicosantangelo
Created October 9, 2014 04:00
Show Gist options
  • Save nicosantangelo/c9375ac3a4876b64d9bf to your computer and use it in GitHub Desktop.
Save nicosantangelo/c9375ac3a4876b64d9bf to your computer and use it in GitHub Desktop.
Print or copy all git commit messages from a single day.
#!/usr/bin/env ruby
require 'optparse'
require 'date'
options = {
branch: '',
day: Date.today.day,
month: Date.today.month,
year: Date.today.year,
author: `git config --global user.email`,
silent: false
}
OptionParser.new do |opts|
opts.banner = "Usage: \n\`command [options]`"
opts.separator ''
opts.separator 'Options:'
opts.on('-b', '--branch BRANCH', 'Branch name. Defaults to the current branch') { |v|
options[:branch] = v
}
opts.on('-d', '--day DAY', 'Day number. Defaults to today') { |v|
options[:day] = v
}
opts.on('-m', '--month MONTH', 'Month number. Defaults to today') { |v|
options[:month] = v
}
opts.on('-y', '--year YEAR', 'Year number. Defaults to today') { |v|
options[:year] = v
}
opts.on('-a', '--authour AUTHOR', 'Author name. Uses the global user as default') { |v|
options[:author] = v
}
opts.on('-s', '--silent', 'Don\'t print to the console. Defaults to false') {
options[:silent] = true
}
opts.separator ''
opts.separator 'By default the script will try to copy the log to clipboard using either pbcopy or xclip (if available)'
end.parse!
def which(cmd)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each { |ext|
exe = File.join(path, "#{cmd}#{ext}")
return exe if File.executable?(exe) && !File.directory?(exe)
}
end
return nil
end
date = "#{options[:year]}-#{options[:month]}-#{options[:day]}"
get_git_messages_command = "git log #{options[:branch]} --after='#{date} 00:00' --before='#{date} 23:59' --author=#{options[:author].chomp} --pretty=format:'%s' | cat"
git_messages = `#{get_git_messages_command}`
if which('pbcopy')
`echo '#{git_messages}' | pbcopy`
elsif which('xclip')
`echo '#{git_messages}' | xclip`
end
puts git_messages unless options[:silent]
@nicosantangelo
Copy link
Author

  1. Download or paste the file into /usr/bin
sudo cp ~/Downloads/git_messages_in_a_day.rb /usr/bin/daymessages
  1. Make the file executable
sudo chmod u+x /usr/bin/daymessages
  1. Profit!
daymessages -h

( no Windows love :( )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment