[TxMt] List all colours in a CSS file command

james at vennt.net james at vennt.net
Wed May 23 11:56:05 UTC 2007

I've made a command which will list all colours in a CSS file as a list of

At the minute it only does Hex colours also I would like it if you could
colours and it would jump to them in your document but I lack the ruby
skills as I'm sure you will notice from the shoddy
"colourArrayToTrim.each" bit.

Anyway some people might find it useful
input:entire document
output:show as HTML
activation:Key cmd+shift+opt+ctrl+c (ALL modifiers + C, to show ALL
colours ;) )
scope: source.css
Code as follows:

#!/usr/bin/env ruby

file = STDIN.read
fileName = ENV['TM_FILENAME']

hex = Regexp.new(/(#(\d|[a-f]|[A-F]){3,6})/)

colourArrayToTrim = file.scan(hex)
colourArray = []
colourArrayToTrim.each { |colour|
    colourArray.push colour.shift

puts '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>


        <style type="text/css" media="screen">
                a {
                        color: #000;
                        text-decoration: none;
                        line-height: 22px;
                        border: 1px solid #fff;
                        padding: 2px;

                a:hover {
                        background-color: #EFEFEF;
                        border: 1px solid #999;

                .colourRow {
                        display: block;
                        margin-top: 5px;
                        margin-bottom: 5px;
                        margin-right: 10px;

                .swatch {
                        width: 20px;
                        height: 20px;
                        display: block;
                        border: 1px solid  #666;
                        margin-right: 10px;
                        float: left;

                .swatch div {
                        width: 18px;
                        height: 18px;
                        border: 1px solid #fff;




puts "<h2>Colours used #{fileName}</h2>"

colourArray.each { |colour|
  puts "
  <a href='' class='colourRow'>
  <div class='swatch'>
  <div style='background-color:#{colour};'></div>

puts "

More information about the textmate mailing list