Skip to content

Instantly share code, notes, and snippets.

@mattfoster
Created January 19, 2015 18:30
Show Gist options
  • Save mattfoster/dc2b6133249cc467d898 to your computer and use it in GitHub Desktop.
Save mattfoster/dc2b6133249cc467d898 to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
# Set iTerm 2 tab colours.
#
# Author: Matt Foster <[email protected]>
require 'color/css'
colour = ARGV.shift
if colour.nil?
puts "Usage: #{$1} colour_name"
exit 1
end
if colour == 'reset'
print "\033]6;1;bg;*;default\a"
exit
end
colour_info = Color::CSS[colour]
if colour_info.nil?
puts "Couldn't process colour name #{colour}"
exit 1
end
red = (colour_info.r * 255).to_i
green = (colour_info.g * 255).to_i
blue = (colour_info.b * 255).to_i
print "\033]6;1;bg;red;brightness;#{red}\a"
print "\033]6;1;bg;green;brightness;#{green}\a"
print "\033]6;1;bg;blue;brightness;#{blue}\a"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment