Skip to content

Instantly share code, notes, and snippets.

@97-109-107
Created April 19, 2015 15:56
Show Gist options
  • Save 97-109-107/24bc2500cf233677b364 to your computer and use it in GitHub Desktop.
Save 97-109-107/24bc2500cf233677b364 to your computer and use it in GitHub Desktop.
This script parses xcolor-type files to the format supported by dynamic-colors https://github.com/sos4nt/dynamic-colors
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-.
require 'pathname'
# This script parses xcolor-type files to the format supported by dynamic-colors
# https://github.com/sos4nt/dynamic-colors
@xcolorsDirPath = ENV['HOME']+'/.config/themer/schemes/'
@destinationFolder = ENV['HOME']+'/.dynamic-colors/colorschemes/'
def convertFile(xcolorsFile)
elements = []
hexes = []
themeName = Pathname.new(xcolorsFile).basename.cleanpath().to_s
IO.foreach(xcolorsFile) do |line|
line = line.strip
if line.start_with?("*.")
line = line.gsub(/\*\./,'')
hex = line.match(/\#\w{6}/)
element = line.match(/\w*\:/)[0].chop
elements << element
hexes << hex
end
end
File.open(@destinationFolder+themeName + '.sh', 'w') do |file|
# Write the definitions
elements.each_with_index do |el, i|
file.write("#{elements[i]}=\"#{hexes[i]}\"\n")
end
# Write the actual assignments
elements.each_with_index do |el, i|
file.write("#{elements[i]}=\"$#{elements[i]}\"\n")
end
end
end
Dir.foreach(@xcolorsDirPath) do |item|
next if item == '.' or item == '..'
convertFile(@xcolorsDirPath + item)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment