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