Skip to content

Instantly share code, notes, and snippets.

Avatar

George gdsmith

View GitHub Profile
@gdsmith
gdsmith / Color Marks.tmCommand
Last active Nov 3, 2018 — forked from sorbits/Color Marks.tmCommand
Textmate command to find, create and add color marks for hex and rgb colors
View Color Marks.tmCommand
#!/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
@gdsmith
gdsmith / Color Marks.tmCommand
Last active Nov 3, 2018
Textmate command to find, create and add color marks for hex and rgb colors
View Color Marks.tmCommand
#!/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]/).
View Color.tmCommand
#!/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
You can’t perform that action at this time.