Automatically change VS Code theme along with Omarchy themes (#800)

* Automatically change VS Code theme along with Omarchy themes

* Create a way to skip vscode auto-theming

* Make theme setting resilient to different states of the settings.json

* Improve setting and removing theme and notify when waiting on install

* Explain what we're doing

* Extract dedicated bin for vscode theme change

---------

Co-authored-by: David Heinemeier Hansson <david@hey.com>
This commit is contained in:
Omar Skalli
2025-09-15 09:20:02 -07:00
committed by GitHub
parent f401c72ea2
commit d3304c4a88
13 changed files with 72 additions and 0 deletions

View File

@@ -60,6 +60,9 @@ fi
# Trigger alacritty config reload
touch "$HOME/.config/alacritty/alacritty.toml"
# Update vscode theme
omarchy-theme-set-vscode
# Restart components to apply new theme
pkill -SIGUSR2 btop
omarchy-restart-waybar

25
bin/omarchy-theme-set-vscode Executable file
View File

@@ -0,0 +1,25 @@
#!/bin/bash
VS_CODE_THEME="$HOME/.config/omarchy/current/theme/vscode.json"
VS_CODE_SETTINGS="$HOME/.config/Code/User/settings.json"
VS_CODE_SKIP_FLAG="$HOME/.local/state/omarchy/toggles/skip-vscode-theme-changes"
if omarchy-cmd-present code && [[ ! -f "$VS_CODE_SKIP_FLAG" ]]; then
if [[ -f "$VS_CODE_THEME" ]]; then
# Install VS Code theme extension
extension=$(jq -r '.extension' "$VS_CODE_THEME")
if [[ -n "$extension" ]] && ! code --list-extensions | grep -Fxq "$extension"; then
notify-send " Installing VS Code theme for $THEME_NAME"
code --install-extension "$extension" >/dev/null
fi
# Update theme in settings.json
theme_name=$(jq -r '.name' "$VS_CODE_THEME")
jq -n --arg t "$theme_name" '(input? // {}) | .["workbench.colorTheme"] = $t' "$VS_CODE_SETTINGS" >"${VS_CODE_SETTINGS}.new"
else
# Remove theme from settings.json when the theme doesn't have vscode support
jq 'del(.["workbench.colorTheme"])' "$VS_CODE_SETTINGS" >"${VS_CODE_SETTINGS}.new"
fi
mv "${VS_CODE_SETTINGS}.new" "$VS_CODE_SETTINGS"
fi

View File

@@ -0,0 +1,4 @@
{
"name": "Catppuccin Latte",
"extension": "catppuccin.catppuccin-vsc"
}

View File

@@ -0,0 +1,4 @@
{
"name": "Catppuccin Macchiato",
"extension": "catppuccin.catppuccin-vsc"
}

View File

@@ -0,0 +1,4 @@
{
"name": "Everforest Dark",
"extension": "sainnhe.everforest"
}

View File

@@ -0,0 +1,4 @@
{
"name": "Gruvbox Dark Medium",
"extension": "jdinhlife.gruvbox"
}

View File

@@ -0,0 +1,4 @@
{
"name": "Kanagawa",
"extension": "qufiwefefwoyn.kanagawa"
}

View File

@@ -0,0 +1,4 @@
{
"name": "Matte Black Theme",
"extension": "cleanthemes.matte-black-theme"
}

4
themes/nord/vscode.json Normal file
View File

@@ -0,0 +1,4 @@
{
"name": "Nord",
"extension": "arcticicestudio.nord-visual-studio-code"
}

View File

@@ -0,0 +1,4 @@
{
"name": "Ocean Green: Dark",
"extension": "jovejonovski.ocean-green"
}

View File

@@ -0,0 +1,4 @@
{
"name": "Monokai Pro (Filter Ristretto)",
"extension": "monokai.theme-monokai-pro-vscode"
}

View File

@@ -0,0 +1,4 @@
{
"name": "Rosé Pine Dawn",
"extension": "mvllow.rose-pine"
}

View File

@@ -0,0 +1,4 @@
{
"name": "Tokyo Night",
"extension": "enkia.tokyo-night"
}