-
-
Save feekApp/3d29b035d839b2665b921ac84f08fc52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
if self.length == 4 | |
self.scan(/[0-9A-Fa-f]/). | |
map {|i| (i*2).to_i(16) } | |
else | |
self.scan(/[0-9A-Fa-f]{2}/). | |
map {|i| i.to_i(16) } | |
end | |
end | |
# rgb to array | |
def rgb2a | |
self.gsub(/[\s\(\)rgba]/,''). | |
split(',')[0,3]. | |
map{|c| c.to_i} | |
end | |
end | |
# extension to Array to divide all elements by 255 | |
# to get decimal rgb value | |
class Array | |
def by255 | |
self.map{|i| (i/255.0).round(4).to_s } | |
end | |
end | |
# template for | |
def get_template() | |
end | |
class ColorBox | |
include ERB::Util | |
attr_accessor :color, :dir | |
Template = %{ | |
%!PS-Adobe-3.0 EPSF-3.0 | |
%%BoundingBox: 0 0 80 80 | |
gsave 0 0 80 80 rectclip gsave | |
<%= @color.join(' ') %> setrgbcolor | |
10 10 70 70 rectfill | |
grestore grestore | |
} | |
def initialize(dir) | |
Dir.mkdir(dir, 0700) unless Dir.exist?(dir) | |
@dir = dir | |
end | |
# set color | |
def set_color(color) | |
@color = get_rgb_array(color) | |
end | |
# get array from color string | |
def get_rgb_array(c) | |
if c[0] == '#' | |
return c.h2a.by255 | |
end | |
if c.match(/^rgb/) | |
return c.rgb2a.by255 | |
end | |
end | |
# render the template | |
def render() | |
ERB.new(Template).result(binding) | |
end | |
# save the file in the given dir unless it exists | |
def save() | |
file = File.join(@dir, @color.join('-')+'.eps') | |
unless File.exists?(file.to_s) | |
File.open(file, "w+") do |f| | |
f.write(render) | |
end | |
end | |
return file.to_s | |
end | |
end | |
def markup | |
dir = "#{ENV['HOME']}/Library/Caches/com.macromates.textmate.colors/" | |
args = [ "--clear-mark=#{dir.shellescape}", "--uuid=#{ENV['TM_DOCUMENT_UUID']}" ] | |
box = ColorBox.new(dir) | |
ARGF.each_with_index do |line, idx| | |
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| | |
box.set_color(c[0]) | |
args << "--line=#{idx+1}" << "--set-mark=#{box.save.shellescape}" | |
} | |
end | |
system(ENV['TM_MATE'], *args) | |
end | |
# fork and redirect output to log | |
pid = fork do | |
FileUtils.mkdir_p("#{ENV['HOME']}/Library/Caches/com.macromates.textmate.colors") | |
STDOUT.reopen(open("#{ENV['HOME']}/Library/Caches/com.macromates.textmate.colors/log.txt", 'w')) | |
STDERR.reopen(open("#{ENV['HOME']}/Library/Caches/com.macromates.textmate.colors/err.txt", 'w')) | |
markup | |
end | |
Process.detach(pid) |
mugsuk
commented
Nov 19, 2023
via email
Thanks for the prompt reply
I also suspect that it is a ruby issue (I do have it installed but wonder if the PATHS or gems are issues) - I have spent some time trying to solve that side of things, but in the end had to finally ask for help.
Anyway, thanks so much again for at least letting me know that it was not an update issue.
Yours sincerely
Murray
… On 19 Nov 2023, at 20:18, feekApp ***@***.***> wrote:
@feekApp commented on this gist.
For me it is still working in Ventura. Do you have ruby installed?
And tbh, I did not writte this code. I found it somewhere on the old Macromates (Textmate) mailinglist.
—
Reply to this email directly, view it on GitHub <https://gist.github.com/feekApp/3d29b035d839b2665b921ac84f08fc52#gistcomment-4765377> or unsubscribe <https://github.com/notifications/unsubscribe-auth/AJHMUCQCXTX2CZWX5GF2VIDYFHFFDBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTCMRVGE3DSMJRU52HE2LHM5SXFJTDOJSWC5DF>.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
hi @mugsuk ,
Now I remember Textmate relies on Ruby 1.8.7
Is the /Users/Mugsuk/Library/Application Support/TextMate/Ruby/1.8.7
directory present on your system? Maybe you can restore this directory from you backup?
Hi @feekApp
The directory is present, but I don’t think textmate is using it to run the command since my default ruby bin is ruby 2.7.4p191 according to “ruby -v”.
I have almost no coding experience so could you please let me know how to get your command to execute with this version of ruby?
Thanks again for your time.
Murray
… On 20 Nov 2023, at 18:31, feekApp ***@***.***> wrote:
@feekApp commented on this gist.
hi @mugsuk <https://github.com/mugsuk> ,
Now I remember Textmate relies on Ruby 1.8.7
Is the /Users/Mugsuk/Library/Application Support/TextMate/Ruby/1.8.7 directory present on your system? Maybe you can restore is directory from you backup?
—
Reply to this email directly, view it on GitHub <https://gist.github.com/feekApp/3d29b035d839b2665b921ac84f08fc52#gistcomment-4766114> or unsubscribe <https://github.com/notifications/unsubscribe-auth/AJHMUCVTYN4T22JWV77KGODYFMBNTBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTCMRVGE3DSMJRU52HE2LHM5SXFJTDOJSWC5DF>.
You are receiving this email because you were mentioned.
Triage notifications on the go with GitHub Mobile for iOS <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
Hi @mugsuk
sorry, I cannot help you more than this. Only this I can do, is share my settings:
under Scope Selector:
source.css, source.css.less
and maybe you should add source.css.scss
under Semantic Class (in order to activate script):
callback.document.did-save, callback.document.did-open, callback.document.did-change-scm-status
Last suggestion ask / search here on the mailinglist
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment