Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ->(){
- # enable tail-call optimization
- RubyVM::InstructionSequence.compile_option = {
- tailcall_optimization: true,
- trace_instruction: false
- }
- mintty2gterm = Module.new{
- # port of rails underscore method, but dasherizing instead
- refine String do
- def dasherize
- self.gsub(/::/, '/').
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1-\2').
- gsub(/([a-z\d])([A-Z])/,'\1-\2').
- tr("_", "-").
- downcase
- end
- end
- # convert dec. color to hex. color
- def to_color_hex
- ->(color){
- str = color.to_i.to_s 16
- str.length < 2 ? "0#{str}" : str
- }
- end
- # get user input
- def user_input
- ->(max_len, index=-1){
- return index if index < max_len && index >= 0
- user_input.call max_len, ARGF.readline.chomp.to_i
- }
- end
- }
- # use monkey patches and include functions
- using mintty2gterm
- include mintty2gterm
- # get profiles and a base dconf dir
- dconfdir="/org/gnome/terminal/legacy/profiles:"
- profiles=(`dconf list #{dconfdir}/`.split "\n")[1...-1]
- # no profile found error
- if profiles.empty?
- warn "No profiles found."
- exit -1
- end
- # profile Selection
- puts "Select profile: (default: 0)"
- profiles.each_with_index do |profile, i|
- puts " (#{i}) => #{profile}"
- end
- print "=> "
- profile = profiles[user_input.call profiles.length]
- # build p
- profile_path = "#{dconfdir}/#{profile}"
- # keys I want to get
- sp_colors = ['Foreground', 'Background', 'Cursor']
- term_colors = ['Black', 'Red', 'Green', 'Yellow', 'Blue', 'Magenta', 'Cyan', 'White']
- # join every
- colors = Array.new.
- concat(sp_colors.map{|col| "#{col}Colour" }).
- concat(term_colors.map{|col| [col, "Bold#{col}"] }.flatten)
- # open minty config and parse colors
- File.open('.minttyrc', 'r'){|file|
- file.each_line{|line|
- key, value = line.split('=')
- next unless colors.include? key
- col = (value.split ',').map{|cmp| to_color_hex.call cmp }.join ''
- puts "#{key.dasherize}: #{col}"
- }
- }
- }.call()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement