├── .travis.yml ├── screen.png ├── lib ├── git_rainbow │ ├── version.rb │ ├── exploder.rb │ └── painter.rb ├── git-rainbow.rb └── git_rainbow.rb ├── bin └── git-rainbow ├── Gemfile ├── .gitignore ├── README.md └── git-rainbow.gemspec /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 2.2.2 4 | -------------------------------------------------------------------------------- /screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaievns/git-rainbow/HEAD/screen.png -------------------------------------------------------------------------------- /lib/git_rainbow/version.rb: -------------------------------------------------------------------------------- 1 | module GitRainbow 2 | VERSION = "1.0.0" 3 | end 4 | -------------------------------------------------------------------------------- /lib/git-rainbow.rb: -------------------------------------------------------------------------------- 1 | # just a hook for the gem 2 | 3 | require_relative "./git_rainbow" 4 | -------------------------------------------------------------------------------- /bin/git-rainbow: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require_relative "../lib/git-rainbow" 4 | 5 | GitRainbow.explode! 6 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in git-rainbow.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | -------------------------------------------------------------------------------- /lib/git_rainbow.rb: -------------------------------------------------------------------------------- 1 | module GitRainbow 2 | end 3 | 4 | require_relative "./git_rainbow/version" 5 | require_relative "./git_rainbow/exploder" 6 | require_relative "./git_rainbow/painter" 7 | -------------------------------------------------------------------------------- /lib/git_rainbow/exploder.rb: -------------------------------------------------------------------------------- 1 | module GitRainbow 2 | extend self 3 | 4 | def explode! 5 | if message 6 | exec command 7 | else 8 | puts usage! 9 | end 10 | end 11 | 12 | def usage! 13 | 'USAGE: git rainbow -m "Your message here!"' 14 | end 15 | 16 | def command 17 | %Q{ git commit #{ammend? ? '--amend' : ''} -m "#{Painter.paint(message)}" } 18 | end 19 | 20 | def message 21 | ARGV.each_with_index do |arg, i| 22 | if arg == "-m" || arg == "--message" 23 | return ARGV[i+1] 24 | end 25 | end 26 | 27 | nil 28 | end 29 | 30 | def ammend? 31 | ARGV.include?("--amend") 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Git::Rainbow 2 | 3 | According to our own research, every year there are millions 4 | of programmers suffer from the lack of rainbows in their git commits. 5 | It is a serious issue, which escalates with age due to the ever 6 | reducing number of dopamine receptors in the brain. 7 | 8 | Lets leave those inhumane working conditions in the past! Introducing 9 | `git rainbow`! 10 | 11 | ``` 12 | gem install git-rainbow 13 | ``` 14 | 15 | Once you have that, go into your project and type: 16 | 17 | ``` 18 | git-rainbow -m 'Adding more rainbows to the project!' 19 | ``` 20 | 21 | It works just like a normal `git commit`, but produces the a rainbowy 22 | commit text. If you've done everything right it should look kind of like 23 | this: 24 | 25 | ![](./screen.png) 26 | 27 | ## Copyright & License 28 | 29 | Mate, you can't patent rainbows! 30 | 31 | -- Nikolay 32 | -------------------------------------------------------------------------------- /git-rainbow.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'git_rainbow/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "git-rainbow" 8 | spec.version = GitRainbow::VERSION 9 | spec.authors = ["Nikolay Nemshilov"] 10 | spec.email = ["nemshilov@gmail.com"] 11 | 12 | spec.summary = "A git extension that makes rainbows" 13 | spec.description = "A git extension that makes rainbows. Like totally!" 14 | spec.homepage = "https://github.com/MadRabbit/git-rainbow" 15 | 16 | spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } 17 | spec.bindir = "bin" 18 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } 19 | spec.require_paths = ["lib"] 20 | 21 | spec.add_dependency "tco", "~> 0.1.8" 22 | spec.add_development_dependency "bundler", "~> 1.9" 23 | end 24 | -------------------------------------------------------------------------------- /lib/git_rainbow/painter.rb: -------------------------------------------------------------------------------- 1 | require "tco" 2 | 3 | module GitRainbow::Painter 4 | extend self 5 | 6 | def paint(message) 7 | palette = build_palette(message.size) 8 | message.chars.map { |ch| colorize(ch, palette.shift) }.join("") 9 | end 10 | 11 | def colorize(char, color) 12 | Tco.fg(color, char) 13 | end 14 | 15 | def build_palette(size) 16 | size.times.map do |i| 17 | # we're basically generating a bunch of sine wave sequences 18 | # with a PI/2 phase shift between them to represent RGB colors 19 | red = wave_value_at(i, size: size, phase: Math::PI/2 - 1) 20 | green = wave_value_at(i, size: size, phase: 0 - 1) 21 | blue = wave_value_at(i, size: size, phase: -Math::PI/2 - 1) 22 | "##{red}#{green}#{blue}" 23 | end 24 | end 25 | 26 | def wave_value_at(i, size: 1, phase: 0) 27 | sin = Math.sin(Math::PI / size * 4 * i + phase) # pure sin -1..+1 value 28 | int = sin * 127 + 128 # 0..255 value 29 | "%02x" % int # 2 symbols hex 30 | end 31 | end 32 | --------------------------------------------------------------------------------