Last active
May 10, 2022 20:53
-
-
Save eoinkelly/910318ffd09599d5646ea7bb2546a07d 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 | |
# 1. save this somewhere on your path as 'retheme' | |
# 2. chmod u+x retheme | |
require 'json' | |
require 'fileutils' | |
THEMES = { | |
# shorthand-name => Actual theme name | |
'default' => 'GitHub Light Default', | |
'light' => 'GitHub Light Default', | |
'dark' => 'GitHub Dark Default', | |
'solarlight' => 'Solarized Light', | |
'solardark' => 'Solarized Dark', | |
'dracula' => 'Dracula', | |
'dark1' => 'Default Dark+', | |
'monokai' => 'Monokai', | |
'nightowl' => 'Night Owl', | |
'nord' => 'Nord', | |
'atom1light' => 'Atom One Light', | |
'tomnight' => 'Tomorrow Night', | |
'tomnightbright' => 'Tomorrow Night Bright' | |
}.freeze | |
puts "Available themes: (pass short name as arg to choose it)" | |
THEMES.each do |short_name, full_name| | |
puts " #{short_name}: #{full_name}" | |
end | |
puts "" | |
def main | |
new_theme_name = ARGV.shift || THEMES.keys.sample | |
new_theme = THEMES.fetch(new_theme_name) | |
cwd = Dir.pwd | |
vscode_settings_dir_path = File.absolute_path(File.join(cwd, '.vscode')) | |
vscode_settings_file = File.absolute_path(File.join(cwd, '.vscode/settings.json')) | |
FileUtils.mkdir(vscode_settings_dir_path) unless Dir.exist?(vscode_settings_dir_path) | |
settings = if File.exist?(vscode_settings_file) | |
JSON.parse(File.read(vscode_settings_file)) | |
else | |
{} | |
end | |
puts "Changing VS Code theme to: #{new_theme}" | |
settings['workbench.colorTheme'] = new_theme | |
File.write(vscode_settings_file, JSON.pretty_generate(settings)) | |
end | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment