Skip to content

Instantly share code, notes, and snippets.

@basicxman
Created June 4, 2011 02:54
Show Gist options
  • Select an option

  • Save basicxman/1007506 to your computer and use it in GitHub Desktop.

Select an option

Save basicxman/1007506 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Processes vim's rgb.txt for colour names!
require 'awesome_print'
def process(s)
s.split(/[A-Z]{1}[a-z]+/).map { |x| x.downcase }.join("_").to_sym
end
data = File.read('./rgb.txt').split("\n")
data.slice! 0
data.each do |line|
args = line.split(/\s+/)
if args.length == 4 # Anything with a space in the colour name can be ignored.
rgb = [args[0].to_i, args[1].to_i, args[2].to_i]
AwesomePrint::Colors.colors.each do |color|
# Check if this is a valid colour.
if color[1] == rgb
puts "#{color[0]}: #{process(args[3])}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment