Created
October 31, 2011 21:24
-
-
Save nevinera/1329002 to your computer and use it in GitHub Desktop.
git log prettification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[alias] | |
lg = "!git log -n 100 --graph --date=short --pretty=tformat:'%h||%cd||%an||%d||%s' | gfix" | |
l = "!git log -n 100 --reverse --date=short --pretty=tformat:'%h||%cd||%an||%d||%s' | gfix" | |
ll = "!git log -n 1000 --reverse --date=short --pretty=tformat:'%h||%cd||%an||%d||%s' | gfix" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
class String | |
COLORS = { | |
:red => "\e[31m", | |
:orange => "\e[33m", | |
:green => "\e[32m", | |
:blue => "\e[34m", | |
:purple => "\e[35m", | |
:teal => "\e[36m", | |
:lgray => "\e[37m", | |
:gray => "\e[30m", | |
} | |
def fixed(n, ellipsis=nil) | |
if self.length > n | |
if ellipsis | |
self.slice(0,n-2) + '..'.colored(ellipsis) | |
else | |
self.slice(0,n) | |
end | |
elsif self.length == n | |
self | |
else | |
self + (" " * (n - self.length)) | |
end | |
end | |
def colored(color) | |
cc = COLORS[color] | |
reset = "\e[0m" | |
if cc | |
cc + self + reset | |
else | |
self | |
end | |
end | |
def uncolored_length | |
s = self.dup | |
COLORS.each_pair do |k,v| | |
s = s.gsub(v,'') | |
end | |
s = s.gsub("\e[0m", '') | |
s.length | |
end | |
def simple_refs | |
return '' unless self =~ /\S/ | |
refs = self.strip.gsub(/[\(\)]/,'').split(/,/) | |
refs.map do |ref| | |
ref.strip. | |
gsub(/HEAD/, 'H'). | |
gsub(/origin/, 'o'). | |
strip. | |
colored(:orange) | |
end. | |
join(','). | |
gsub(/,/, ",".colored(:gray)) | |
end | |
def right_overlay(little, ecolor=nil) | |
left_part = self.strip.fixed(self.length - little.uncolored_length - 1, ecolor) | |
left_part + " " + little | |
end | |
end | |
inlines = [] | |
widest_tree = 0 | |
begin | |
ARGF.each_line do |ln| | |
inlines << ln | |
if ln =~ /\w{6}/ and not ln =~ /^\w{6}/ | |
tree = ln.slice(0, ln =~ /\w/) | |
widest_tree = [widest_tree, tree.length].max | |
end | |
end | |
end | |
begin | |
inlines.each do |ln| | |
if ln =~ /\w{5}/ | |
tree = "" | |
unless ln =~ /^\w{6}/ | |
tree = ln.slice(0, ln =~ /\w/) | |
ln = ln.slice(tree.length, 10000) | |
end | |
chash, date, author, refs, subject = ln.chomp.split '||' | |
fname = author.strip.split(/\s+/).first | |
out = "" | |
out += tree.fixed(widest_tree) | |
out += "#{chash.colored(:red)} " | |
out += "#{date.colored(:green)} " | |
if refs and refs =~ /\S/ | |
out += "#{subject.fixed(80).right_overlay(refs.simple_refs, :gray) } " | |
else | |
out += "#{subject.fixed(80, :gray)} " | |
end | |
out += "#{fname.fixed(5).colored(:gray)} " | |
puts out | |
else | |
puts ln | |
end | |
end | |
rescue Errno::EPIPE | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment