Skip to content

Instantly share code, notes, and snippets.

@hayduke19us
Created January 7, 2014 07:28
Show Gist options
  • Save hayduke19us/8295820 to your computer and use it in GitHub Desktop.
Save hayduke19us/8295820 to your computer and use it in GitHub Desktop.
require 'yaml'
require 'colorize'
file = Dir.pwd + "/themes.yml"
puts "1. Rate theme"
puts "=-=-=-=-=-=--=-=-=-=-=-="
puts "2. List all rated themes"
puts "=-=-=-=-=-=-=-=-=-=-=-=-"
input = gets.chomp
if input.to_i == 1
puts "Name of theme?"
theme = gets.chomp
puts "Theme rating? (1-10)"
rating = gets.chomp.to_i
unless File.exist?(file)
File.open(file, 'w') do |f|
f.puts({theme => rating}.to_yaml)
f.close
end
else
data = YAML.load_file(file)
data[theme] = rating.to_i
File.open(file, 'w+') {|f| YAML.dump(data, f)}
end
elsif
data = YAML.load_file(file)
data = data.sort_by {|k, v| v}
data = data.reverse
best_theme = data.first
@chosen = best_theme.first.dup
puts "* " + @chosen.to_s.colorize(:green) + " *" +
" is your highest rated theme"
puts "Would you like me to change your zsh to that theme? (y|n)"
puts "=-=-=-=-=-=-=-=-=-=-=-=-"
data.each {|t| p t.join(": ")}
puts "=-=-=-=-=-=-=-=-=-=-=-=-"
input = gets.chomp
if input =~ /\A(y|yes)/
puts "ok"
puts %{=-=-=-=}
20.times do |t|
sleep(1.0/24)
print ".".colorize(:green)
end
puts "done"
file = Dir.home + "/.zshrc"
if File.exist?(file)
puts "we found your zsh config file in #{file}"
file = File.open(file, 'a+')
all = file.readlines
puts all.class
all.each do |line|
if line =~ /ZSH_THEME="/
@tmp = line
end
end
puts all.index(@tmp)
all[7] = "ZSH_THEME=" + "'" + "#{@chosen}" + "'"
File.open(Dir.home + "/.zshrc", 'w') do |file|
all.each do |a|
file.puts a
end
end
else
puts "we havn't found it yet"
end
end
end
puts "change back to random?(y|n)"
input = gets.chomp
def change_theme
file = Dir.home + "/.zshrc"
if File.exist?(file)
puts "we found your zsh config file in #{file}"
file = File.open(file, 'a+')
all = file.readlines
puts all.class
all.each do |line|
if line =~ /ZSH_THEME="/
@tmp = line
end
end
puts all.index(@tmp)
all[7] = "ZSH_THEME='random'"
File.open(Dir.home + "/.zshrc", 'w') do |file|
all.each do |a|
file.puts a
end
end
else
puts "we havn't found it yet"
end
end
if input =~ /\A(y|yes)/
change_theme
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment