Skip to content

Instantly share code, notes, and snippets.

@andrew-carroll
Created November 3, 2015 22:43
Show Gist options
  • Save andrew-carroll/35746a21043812091cab to your computer and use it in GitHub Desktop.
Save andrew-carroll/35746a21043812091cab to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
pwd = `pwd`.strip
targets = if ARGV.empty?
Dir["#{pwd}/*"]
else
ARGV.map do |arg|
Dir["#{arg.strip.gsub(/\/*$/,'')}/*"]
end.flatten.uniq
end
targets.each do |target|
target.gsub!(/#{pwd}/, '.')
last_commit = `git log -- #{target}`
longest_line_length = last_commit.lines.map(&:length).max || 60
max_length = longest_line_length > 60 ? longest_line_length : 60
header = [
".#{'-' * (max_length - 2)}.",
"| #{target.ljust(max_length - 3)}|",
"|#{'-' * (max_length - 2)}|"
]
footer = ["`#{'-' * (max_length - 2)}x"].join("\n")
formatted = last_commit.lines.map do |line|
"| #{line.strip.ljust(max_length - 4)} |"
end
puts header, formatted, footer
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment