#!/usr/bin/env python3 import re from argparse import ArgumentParser from pathlib import Path if __name__ == "__main__": parser = ArgumentParser(description="VS Code theme switcher") parser.add_argument( "mode", help="The mode to switch the VS Code theme to (e.g., 'dark' or 'light')", ) args = parser.parse_args() if args.mode not in ["dark", "light"]: print("Invalid mode. Please choose 'dark' or 'light'.") exit(1) settings = Path.home() / ".config/Code/User/settings.json" if not settings.exists(): print(f"VS Code settings file not found at {settings}") exit(1) # We just replace the theme name in the settings file using regex, # this way we don't have to worry about jsonc parsing. theme = "Monokai Pro" if args.mode == "dark" else "Monokai Pro Light" with settings.open("r") as f: content = f.read() new_content = re.sub( r'"workbench\.colorTheme"\s*:\s*".*?"', f'"workbench.colorTheme": "{theme}"', content, ) with settings.open("w") as f: f.write(new_content)