Skip to content

Instantly share code, notes, and snippets.

@gdsmith
gdsmith / Color Marks.tmCommand
Last active April 19, 2024 19:23
Textmate command to find, create and add color marks for hex and rgb colors
#!/usr/bin/env ruby -wU
require 'erb'
# extension to String to extract colours into rgb array
class String
# hex to array
def h2a
if self.length == 4
self.scan(/[0-9A-Fa-f]/).
@gdsmith
gdsmith / Color Marks.tmCommand
Last active September 13, 2022 13:16 — forked from sorbits/Color Marks.tmCommand
Textmate command to find, create and add color marks for hex and rgb colors
#!/usr/bin/env ruby -wU
require 'erb'
require 'fileutils'
require 'shellwords'
# extension to String to extract colours into rgb array
class String
# hex to array
def h2a
#!/usr/bin/env ruby18 -wKU
line = ENV['TM_CURRENT_LINE'] || ENV['TM_SELECTED_TEXT']
color = ''
line.scan(/(#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})(?=[^0-9A-Fa-f])|rgba{0,1}\([0-9]{1,3}[, ]+?[0-9]{1,3}[, ]+?[0-9]{1,3}[, 0-9\.]*?\))/) { |c|
color = color+"<div style='font-size:8px;display:inline-block;height:3em;margin:0;padding:0 0.5em 0 0;height:3em;background:#{c[0]}'><span style='background:#000;color:#FFF'>#{c[0]}</span></div>"
}
color = '<div style=\\"background:\\#000;color:\\#FFF;padding:2px\\">No color found</div>' unless color.length > 0