Last active
October 5, 2015 19:27
-
-
Save sfate/2862863 to your computer and use it in GitHub Desktop.
Colored one line output from git-log
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
curl http://git.io/git-log-simplify.rb --create-dirs -Lo $HOME/bin/git-lg | |
chmod +x $HOME/bin/git-lg |
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/env ruby | |
# | |
# Author: | |
# Sfate(https://github.com/Sfate) | |
# | |
# Description: | |
# Show `git log` in simple colored list | |
# | |
# Install: | |
# $ curl -Lo- http://git.io/log-simplify.sh | bash | |
# | |
# Run: | |
# # Navigate to your project and type(shows 10 commits by default): | |
# $ git lg | |
# # To show 20 commits: | |
# $ git lg 20 | |
# | |
# Share me: | |
# https://gist.github.com/2862863 | |
# | |
ARGV << "-n10" unless ARGV.any?{|arg| arg.include?("-n")} | |
module Color | |
def self.red(text); colorize(text, "\e[1m\e[31m"); end | |
def self.green(text); colorize(text, "\e[1m\e[32m"); end | |
def self.dark_green(text); colorize(text, "\e[32m"); end | |
def self.yellow(text); colorize(text, "\e[1m\e[33m"); end | |
def self.blue(text); colorize(text, "\e[1m\e[34m"); end | |
def self.dark_blue(text); colorize(text, "\e[34m"); end | |
def self.pur(text); colorize(text, "\e[1m\e[35m"); end | |
def self.colorize(text, color_code) "#{color_code}#{text}\e[0m" end | |
end | |
colorize = lambda{|s, i| | |
case i | |
when 0; Color::yellow(s) | |
when 1; Color::red(s[0..28].ljust(29)) | |
when 2; Color::green(s[0..36].ljust(37)) | |
when 3; Color::blue(s[0..13].ljust(14)) | |
else; Color::pur(s[0..23].ljust(24)) | |
end | |
} | |
commits_list = %x[git log --pretty=format:"%H::::%ae::::%s::::%ar::::%ad" --no-merges #{ARGV.join(" ")}] | |
commits_list = commits_list.split("\n").map { |a| a.split('::::').each_with_index.map(&colorize).join("\s") } | |
puts commits_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment