Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hagmonk/42758 to your computer and use it in GitHub Desktop.
Save hagmonk/42758 to your computer and use it in GitHub Desktop.
#!/usr/bin/env arch -i386 ruby
# TextMate's default insert color command is pretty lame. I wanted it to detect
# rgb values and use those, outputting the same if detected. Here's my first naive
# cut at improving this script. I think it should fall through a few different
# filters, trying to detect whether it's hex, rgb, or a color name (who uses those?!)
require ENV['TM_SUPPORT_PATH'] + "/lib/ui"
require ENV['TM_SUPPORT_PATH'] + "/lib/exit_codes"
colour = STDIN.read
was_hex = true
if colour.length > 0 and colour[0] != ?#
was_hex = false
if md = colour.match(/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/) and md.length == 4
colour = '#' + md[1,3].map { |c| "%0.2X" % c }.join("")
end
end
if res = TextMate::UI.request_color(colour)
if was_hex == false
print [res.delete("#")].pack("H*").unpack("C*").join(", ")
else
print res
end
else
TextMate.exit_discard
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment