[TxMt] Insert Color Revised (help needed)

Charilaos Skiadas skiadas at hanover.edu
Sat Oct 21 05:19:20 UTC 2006


On Oct 20, 2006, at 10:42 PM, Brett Terpstra wrote:

> It works, but I'd really like to see it cleaned up (I know Haris  
> could do this in about 4 lines of code).  So if anyone has the  
> time... It'd be great to learn a new algorithm to handle this.

Well, since you asked for it ;) I'm sure JEG2 can shorten this  
further, but here is my take on it. I've attached the command, and  
appended the actual code.

Perhaps we should add this to the CSS bundle?

Haris

#!/usr/bin/env ruby
string = STDIN.read
prefix, string = string.match(/(#?)(.*)/)[1,2]
string = $1 * 2 + $2 * 2 + $3 * 2 if string =~ /^(.)(.)(.)$/
def_col = ' default color {' + string.scan(/../).map { |i| i.hex *  
257 }.join(",") + '}'
col = `osascript 2>/dev/null -e 'tell app "TextMate" to choose color# 
{def_col}'`
exit 200 if col == ""
col=col.scan(/\d+/).map { |i| "%02X" % (i.to_i / 257) }.join("")
print prefix
if col.match(/(.)\1(.)\2(.)\3/) then
   print $1 + $2 + $3
else
   print col
end

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Insert Color revised copy2.tmCommand
Type: application/octet-stream
Size: 1250 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20061021/af4bab29/attachment.tmCommand>


More information about the textmate mailing list