Simplify the VSCode/derivatives theme setting

This commit is contained in:
David Heinemeier Hansson
2026-01-08 10:22:10 +01:00
parent 5603fb50fd
commit 9fc65dd2de
4 changed files with 23 additions and 39 deletions

View File

@@ -56,8 +56,6 @@ omarchy-restart-mako
omarchy-theme-set-gnome omarchy-theme-set-gnome
omarchy-theme-set-browser omarchy-theme-set-browser
omarchy-theme-set-vscode omarchy-theme-set-vscode
omarchy-theme-set-vscodium
omarchy-theme-set-cursor
omarchy-theme-set-obsidian omarchy-theme-set-obsidian
# Call hook on theme set # Call hook on theme set

View File

@@ -1,4 +0,0 @@
#!/bin/bash
# Call the VSCode theme setter with Cursor-specific parameters
omarchy-theme-set-vscode cursor "$HOME/.config/Cursor/User/settings.json" "$HOME/.local/state/omarchy/toggles/skip-cursor-theme-changes"

View File

@@ -1,45 +1,39 @@
#!/bin/bash #!/bin/bash
# Note: We cannot use `jq` to update settings.json because its JSONC (allows comments), # Sync Omarchy theme to VS Code, VSCodium, and Cursor
# which jq doesnt support.
# Parameters: EDITOR_CMD SETTINGS_PATH SKIP_FLAG EDITOR_NAME
EDITOR_CMD="${1:-code}"
SETTINGS_PATH="${2:-$HOME/.config/Code/User/settings.json}"
SKIP_FLAG="${3:-$HOME/.local/state/omarchy/toggles/skip-vscode-theme-changes}"
VS_CODE_THEME="$HOME/.config/omarchy/current/theme/vscode.json" VS_CODE_THEME="$HOME/.config/omarchy/current/theme/vscode.json"
if omarchy-cmd-present "$EDITOR_CMD" && [[ ! -f "$SKIP_FLAG" ]]; then set_theme() {
local editor_cmd="$1"
local settings_path="$2"
local skip_flag="$3"
omarchy-cmd-present "$editor_cmd" && [[ ! -f "$skip_flag" ]] || return 0
if [[ -f "$VS_CODE_THEME" ]]; then if [[ -f "$VS_CODE_THEME" ]]; then
theme_name=$(jq -r '.name' "$VS_CODE_THEME") theme_name=$(jq -r '.name' "$VS_CODE_THEME")
extension=$(jq -r '.extension' "$VS_CODE_THEME") extension=$(jq -r '.extension' "$VS_CODE_THEME")
# Install theme extension if [[ -n "$extension" ]] && ! "$editor_cmd" --list-extensions | grep -Fxq "$extension"; then
if [[ -n "$extension" ]] && ! "$EDITOR_CMD" --list-extensions | grep -Fxq "$extension"; then "$editor_cmd" --install-extension "$extension" >/dev/null
"$EDITOR_CMD" --install-extension "$extension" >/dev/null
fi fi
# Create config file if there isn't already one mkdir -p "$(dirname "$settings_path")"
mkdir -p "$(dirname "$SETTINGS_PATH")" [[ -f "$settings_path" ]] || printf '{\n}\n' >"$settings_path"
if [[ ! -f "$SETTINGS_PATH" ]]; then
printf '{\n}\n' >"$SETTINGS_PATH" if ! grep -q '"workbench.colorTheme"' "$settings_path"; then
sed -i --follow-symlinks -E '0,/\{/{s/\{/{\ "workbench.colorTheme": "",/}' "$settings_path"
fi fi
# Create a `workbench.colorTheme` entry in settings.
if ! grep -q '"workbench.colorTheme"' "$SETTINGS_PATH"; then
# Insert `"workbench.colorTheme": "",` immediately after the first `{`
# Use sed's first-match range (0,/{/) to only replace the first `{`
sed -i --follow-symlinks -E '0,/\{/{s/\{/{\ "workbench.colorTheme": "",/}' "$SETTINGS_PATH"
fi
# Update theme
sed -i --follow-symlinks -E \ sed -i --follow-symlinks -E \
"s/(\"workbench.colorTheme\"[[:space:]]*:[[:space:]]*\")[^\"]*(\")/\1$theme_name\2/" \ "s/(\"workbench.colorTheme\"[[:space:]]*:[[:space:]]*\")[^\"]*(\")/\1$theme_name\2/" \
"$SETTINGS_PATH" "$settings_path"
else elif [[ -f "$settings_path" ]]; then
# Remove theme from settings.json when the theme doesn't have editor support sed -i --follow-symlinks -E 's/\"workbench\.colorTheme\"[[:space:]]*:[^,}]*,?//' "$settings_path"
if [[ -f "$SETTINGS_PATH" ]]; then
sed -i --follow-symlinks -E 's/\"workbench\.colorTheme\"[[:space:]]*:[^,}]*,?//' "$SETTINGS_PATH"
fi
fi fi
fi }
set_theme "code" "$HOME/.config/Code/User/settings.json" "$HOME/.local/state/omarchy/toggles/skip-vscode-theme-changes"
set_theme "codium" "$HOME/.config/VSCodium/User/settings.json" "$HOME/.local/state/omarchy/toggles/skip-codium-theme-changes"
set_theme "cursor" "$HOME/.config/Cursor/User/settings.json" "$HOME/.local/state/omarchy/toggles/skip-cursor-theme-changes"

View File

@@ -1,4 +0,0 @@
#!/bin/bash
# Call the VSCode theme setter with VSCodium-specific parameters
omarchy-theme-set-vscode codium "$HOME/.config/VSCodium/User/settings.json" "$HOME/.local/state/omarchy/toggles/skip-codium-theme-changes"