92 lines
3.1 KiB
Bash
Executable File
92 lines
3.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# omarchy:summary=Sync Omarchy theme to VS Code, VSCodium, and Cursor
|
|
# omarchy:hidden=true
|
|
|
|
VS_CODE_THEME="$HOME/.config/omarchy/current/theme/vscode.json"
|
|
GENERATED_THEME="$HOME/.config/omarchy/current/theme/vscode-theme.json"
|
|
|
|
# Install generated theme as a local extension for a given editor
|
|
install_generated_extension() {
|
|
local ext_dir="$1"
|
|
local theme_type ui_theme
|
|
|
|
theme_type=$(jq -r '.type // "dark"' "$GENERATED_THEME")
|
|
if [[ $theme_type == "light" ]]; then
|
|
ui_theme="vs"
|
|
else
|
|
ui_theme="vs-dark"
|
|
fi
|
|
|
|
mkdir -p "$ext_dir/themes"
|
|
cp "$GENERATED_THEME" "$ext_dir/themes/omarchy-color-theme.json"
|
|
|
|
cat > "$ext_dir/package.json" <<EOF
|
|
{
|
|
"name": "omarchy-theme",
|
|
"displayName": "Omarchy",
|
|
"description": "Omarchy color theme",
|
|
"publisher": "local",
|
|
"version": "1.0.0",
|
|
"engines": { "vscode": "^1.70.0" },
|
|
"categories": ["Themes"],
|
|
"contributes": {
|
|
"themes": [{
|
|
"label": "Omarchy",
|
|
"uiTheme": "$ui_theme",
|
|
"path": "./themes/omarchy-color-theme.json"
|
|
}]
|
|
}
|
|
}
|
|
EOF
|
|
}
|
|
|
|
set_theme() {
|
|
local editor_cmd="$1"
|
|
local settings_path="$2"
|
|
local ext_base="$3"
|
|
|
|
omarchy-cmd-present "$editor_cmd" || return 0
|
|
|
|
local theme_name=""
|
|
|
|
# Always deploy the generated theme so it's available in the theme picker
|
|
if [[ -f "$GENERATED_THEME" ]]; then
|
|
install_generated_extension "$ext_base/omarchy-theme"
|
|
fi
|
|
|
|
if [[ -f "$VS_CODE_THEME" ]]; then
|
|
# Theme specifies a preferred 3rd-party extension
|
|
theme_name=$(jq -r '.name' "$VS_CODE_THEME")
|
|
local extension
|
|
extension=$(jq -r '.extension' "$VS_CODE_THEME")
|
|
|
|
if [[ -n $extension ]] && ! "$editor_cmd" --list-extensions 2>/dev/null | grep -Fxq "$extension"; then
|
|
"$editor_cmd" --install-extension "$extension" >/dev/null 2>&1
|
|
fi
|
|
elif [[ -f "$GENERATED_THEME" ]]; then
|
|
# No 3rd-party preference, activate the generated theme
|
|
theme_name="Omarchy"
|
|
fi
|
|
|
|
if [[ -n "$theme_name" ]]; then
|
|
mkdir -p "$(dirname "$settings_path")"
|
|
[[ -f $settings_path ]] || 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
|
|
|
|
sed -i --follow-symlinks -E \
|
|
"s/(\"workbench.colorTheme\"[[:space:]]*:[[:space:]]*\")[^\"]*(\")/\1$theme_name\2/" \
|
|
"$settings_path"
|
|
elif [[ -f $settings_path ]]; then
|
|
sed -i --follow-symlinks -E 's/\"workbench\.colorTheme\"[[:space:]]*:[^,}]*,?//' "$settings_path"
|
|
fi
|
|
}
|
|
|
|
! omarchy-toggle-enabled skip-vscode-theme-changes && set_theme "code" "$HOME/.config/Code/User/settings.json" "$HOME/.vscode/extensions"
|
|
! omarchy-toggle-enabled skip-vscode-insiders-theme-changes && set_theme "code-insiders" "$HOME/.config/Code - Insiders/User/settings.json" "$HOME/.vscode-insiders/extensions"
|
|
! omarchy-toggle-enabled skip-codium-theme-changes && set_theme "codium" "$HOME/.config/VSCodium/User/settings.json" "$HOME/.vscode-oss/extensions"
|
|
! omarchy-toggle-enabled skip-cursor-theme-changes && set_theme "cursor" "$HOME/.config/Cursor/User/settings.json" "$HOME/.cursor/extensions"
|