Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.10 KB | None | 0 0
  1. ->(){
  2.  
  3.   # enable tail-call optimization
  4.   RubyVM::InstructionSequence.compile_option = {
  5.     tailcall_optimization: true,
  6.     trace_instruction: false
  7.   }
  8.  
  9.   mintty2gterm = Module.new{
  10.  
  11.     # port of rails underscore method, but dasherizing instead
  12.     refine String do
  13.       def dasherize
  14.         self.gsub(/::/, '/').
  15.           gsub(/([A-Z]+)([A-Z][a-z])/,'\1-\2').
  16.           gsub(/([a-z\d])([A-Z])/,'\1-\2').
  17.           tr("_", "-").
  18.           downcase
  19.       end
  20.     end
  21.  
  22.     # convert dec. color to hex. color
  23.     def to_color_hex
  24.       ->(color){
  25.         str = color.to_i.to_s 16
  26.         str.length < 2 ? "0#{str}" : str
  27.       }
  28.     end
  29.  
  30.     # get user input
  31.     def user_input
  32.       ->(max_len, index=-1){
  33.         return index if index < max_len && index >= 0
  34.         user_input.call max_len, ARGF.readline.chomp.to_i
  35.       }
  36.     end
  37.  
  38.   }
  39.  
  40.   # use monkey patches and include functions
  41.   using mintty2gterm
  42.   include mintty2gterm
  43.  
  44.   # get profiles and a base dconf dir
  45.   dconfdir="/org/gnome/terminal/legacy/profiles:"
  46.   profiles=(`dconf list #{dconfdir}/`.split "\n")[1...-1]
  47.  
  48.   # no profile found error
  49.   if profiles.empty?
  50.     warn "No profiles found."
  51.     exit -1
  52.   end
  53.  
  54.   # profile Selection
  55.   puts "Select profile:  (default: 0)"
  56.   profiles.each_with_index do |profile, i|
  57.     puts "  (#{i}) => #{profile}"
  58.   end
  59.   print "=> "
  60.   profile = profiles[user_input.call profiles.length]
  61.  
  62.   # build p
  63.   profile_path = "#{dconfdir}/#{profile}"
  64.  
  65.   # keys I want to get
  66.   sp_colors = ['Foreground', 'Background', 'Cursor']
  67.   term_colors = ['Black', 'Red', 'Green', 'Yellow', 'Blue', 'Magenta', 'Cyan', 'White']
  68.  
  69.   # join every
  70.   colors = Array.new.
  71.     concat(sp_colors.map{|col| "#{col}Colour" }).
  72.     concat(term_colors.map{|col| [col, "Bold#{col}"] }.flatten)
  73.  
  74.   # open minty config and parse colors
  75.   File.open('.minttyrc', 'r'){|file|
  76.     file.each_line{|line|
  77.       key, value = line.split('=')
  78.       next unless colors.include? key
  79.       col = (value.split ',').map{|cmp| to_color_hex.call cmp }.join ''
  80.       puts "#{key.dasherize}: #{col}"
  81.     }
  82.   }
  83.  
  84. }.call()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement