Created
January 3, 2009 00:57
-
-
Save hagmonk/42758 to your computer and use it in GitHub Desktop.
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 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