Created
July 13, 2022 20:29
-
-
Save eoinkelly/5580ffea49c9f53454819b1fa66589c2 to your computer and use it in GitHub Desktop.
Choose a random VSCode theme for your current project
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 | |
# Purpose: | |
# | |
# * Edits .vscode/settings.json file to set a new theme for the project. | |
# * If no arg passed then a theme is chosen randomly. | |
# * You must already have the themes installed | |
# * You should edit the list of themes to match your favourites. | |
# | |
# Installation: | |
# | |
# 1.Download this file and save as 'retheme' in some directory on your PATH | |
# 2. Run: chmod u+x path/to/downloaded/file | |
# | |
# Usage: | |
# $ cd path/to/root/of/a/vscode/project | |
# $ retheme # choose a random theme | |
# $ retheme light # choose the 'light' theme | |
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