Clean up semantic theme compatibility

This commit is contained in:
Ryan Hughes
2026-06-02 19:35:07 -04:00
parent 89bfa841c4
commit 4087be7f79
4 changed files with 86 additions and 78 deletions
+16 -34
View File
@@ -182,24 +182,6 @@ selection_background=${selection_background:-$foreground}
selection_foreground=${selection_foreground:-$background}
accent=$color4
# Remap ANSI slots to semantic names for the output palette
bg=$color0
red=$color1
green=$color2
yellow=$color3
blue=$color4
purple=$color5
cyan=$color6
fg=$color7
muted=$color8
bright_red=$color9
bright_green=$color10
bright_yellow=$color11
bright_blue=$color12
bright_purple=$color13
bright_cyan=$color14
bright_fg=$color15
mkdir -p "$THEME_SOURCE"
cat > "$COLORS_OUTPUT" <<EOF
@@ -210,20 +192,20 @@ background = "$background"
selection_foreground = "$selection_foreground"
selection_background = "$selection_background"
color0 = "$bg"
color1 = "$red"
color2 = "$green"
color3 = "$yellow"
color4 = "$blue"
color5 = "$purple"
color6 = "$cyan"
color7 = "$fg"
color8 = "$muted"
color9 = "$bright_red"
color10 = "$bright_green"
color11 = "$bright_yellow"
color12 = "$bright_blue"
color13 = "$bright_purple"
color14 = "$bright_cyan"
color15 = "$bright_fg"
color0 = "$color0"
color1 = "$color1"
color2 = "$color2"
color3 = "$color3"
color4 = "$color4"
color5 = "$color5"
color6 = "$color6"
color7 = "$color7"
color8 = "$color8"
color9 = "$color9"
color10 = "$color10"
color11 = "$color11"
color12 = "$color12"
color13 = "$color13"
color14 = "$color14"
color15 = "$color15"
EOF
+7 -11
View File
@@ -3,20 +3,19 @@
# omarchy:summary=Apply the current theme to GNOME color mode and icon settings
# omarchy:hidden=true
# Detect mode (light|dark) with this precedence:
# 1. `mode` key in the active theme's colors.toml
# 2. legacy `light.mode` file shipped beside the theme
THEME_DIR=~/.config/omarchy/current/theme
COLORS_FILE="$THEME_DIR/colors.toml"
theme_color() {
local key="$1"
# In-tree light themes now declare `mode = "light"` in colors.toml instead of
# shipping a separate light.mode marker. Keep light.mode as a user-theme fallback.
theme_mode() {
[[ -f $COLORS_FILE ]] || return
awk -F= -v key="$key" '
awk -F= '
{
field = $1
gsub(/^[[:space:]]+|[[:space:]]+$/, "", field)
if (field == key) {
if (field == "mode") {
value = $2
gsub(/^[[:space:]]+|[[:space:]]+$/, "", value)
if (value ~ /^"/) {
@@ -30,10 +29,7 @@ theme_color() {
' "$COLORS_FILE"
}
mode=""
if [[ -f $COLORS_FILE ]]; then
mode=$(theme_color mode)
fi
mode=$(theme_mode)
if [[ -z $mode && -f $THEME_DIR/light.mode ]]; then
mode="light"
fi
+56 -22
View File
@@ -290,6 +290,30 @@ add_gradient_function_values() {
done
}
alias_theme_color() {
local key="$1"
local fallback="$2"
[[ ${THEME_COLORS[$key]} ]] || THEME_COLORS[$key]="${THEME_COLORS[$fallback]}"
}
resolve_theme_mode() {
local bg_hex lum
[[ ${THEME_COLORS[mode]} ]] || THEME_COLORS[mode]="${THEME_COLORS[theme_type]}"
[[ ${THEME_COLORS[mode]} ]] && return
if [[ -f $NEXT_THEME_DIR/light.mode ]]; then
THEME_COLORS[mode]="light"
elif [[ ${THEME_COLORS[background]} =~ ^#[0-9A-Fa-f]{6}$ ]]; then
bg_hex="${THEME_COLORS[background]#\#}"
lum=$(( $(printf "%d" "0x${bg_hex:0:2}") + $(printf "%d" "0x${bg_hex:2:2}") + $(printf "%d" "0x${bg_hex:4:2}") ))
(( lum > 382 )) && THEME_COLORS[mode]="light" || THEME_COLORS[mode]="dark"
else
THEME_COLORS[mode]="dark"
fi
}
# Only generate dynamic templates for themes with a colors.toml definition
if [[ -f $COLORS_FILE ]]; then
sed_script=$(mktemp)
@@ -308,14 +332,23 @@ if [[ -f $COLORS_FILE ]]; then
# Legacy compatibility: map ANSI color0..color15 and raw bg/fg to semantic names
declare -A legacy_alias=(
[bg]=background [fg]=foreground
[red]=color1 [green]=color2 [yellow]=color3
[blue]=color4 [purple]=color5 [cyan]=color6
[bright_red]=color9 [bright_green]=color10 [bright_yellow]=color11
[bright_blue]=color12 [bright_purple]=color13 [bright_cyan]=color14
[bg]=background
[fg]=foreground
[red]=color1
[green]=color2
[yellow]=color3
[blue]=color4
[purple]=color5
[cyan]=color6
[bright_red]=color9
[bright_green]=color10
[bright_yellow]=color11
[bright_blue]=color12
[bright_purple]=color13
[bright_cyan]=color14
)
for key in "${!legacy_alias[@]}"; do
[[ ${THEME_COLORS[$key]} ]] || THEME_COLORS[$key]="${THEME_COLORS[${legacy_alias[$key]}]}"
alias_theme_color "$key" "${legacy_alias[$key]}"
done
[[ ${THEME_COLORS[light_fg]} ]] || THEME_COLORS[light_fg]="${THEME_COLORS[color7]:-${THEME_COLORS[foreground]}}"
@@ -340,15 +373,25 @@ if [[ -f $COLORS_FILE ]]; then
# Keep semantic themes compatible with user templates that still reference
# the legacy ANSI placeholders directly.
declare -A ansi_alias=(
[color0]=bg [color1]=red [color2]=green
[color3]=yellow [color4]=blue [color5]=purple
[color6]=cyan [color7]=fg [color8]=muted
[color9]=bright_red [color10]=bright_green [color11]=bright_yellow
[color12]=bright_blue [color13]=bright_purple [color14]=bright_cyan
[color0]=bg
[color1]=red
[color2]=green
[color3]=yellow
[color4]=blue
[color5]=purple
[color6]=cyan
[color7]=fg
[color8]=muted
[color9]=bright_red
[color10]=bright_green
[color11]=bright_yellow
[color12]=bright_blue
[color13]=bright_purple
[color14]=bright_cyan
[color15]=bright_fg
)
for key in "${!ansi_alias[@]}"; do
[[ ${THEME_COLORS[$key]} ]] || THEME_COLORS[$key]="${THEME_COLORS[${ansi_alias[$key]}]}"
alias_theme_color "$key" "${ansi_alias[$key]}"
done
# Resolve theme mode (dark|light) with this precedence:
@@ -356,16 +399,7 @@ if [[ -f $COLORS_FILE ]]; then
# 2. legacy `light.mode` file shipped beside the theme
# 3. background luminance auto-detect
# `theme_type` is kept as an alias so existing templates ({{ theme_type }}) keep working.
[[ ${THEME_COLORS[mode]} ]] || THEME_COLORS[mode]="${THEME_COLORS[theme_type]}"
if [[ ! ${THEME_COLORS[mode]} ]]; then
if [[ -f $NEXT_THEME_DIR/light.mode ]]; then
THEME_COLORS[mode]="light"
else
bg_hex="${THEME_COLORS[background]#\#}"
lum=$(( $(printf "%d" "0x${bg_hex:0:2}") + $(printf "%d" "0x${bg_hex:2:2}") + $(printf "%d" "0x${bg_hex:4:2}") ))
[[ $lum -gt 382 ]] && THEME_COLORS[mode]="light" || THEME_COLORS[mode]="dark"
fi
fi
resolve_theme_mode
THEME_COLORS[theme_type]="${THEME_COLORS[mode]}"
for key in "${!THEME_COLORS[@]}"; do
+7 -11
View File
@@ -3,7 +3,7 @@
# omarchy:summary=Sync Omarchy theme to VS Code, VSCodium, and Cursor
# omarchy:hidden=true
VS_CODE_THEME="$HOME/.config/omarchy/current/theme/vscode.json"
VS_CODE_THEME_DESCRIPTOR="$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
@@ -50,22 +50,18 @@ set_theme() {
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")
if [[ -f "$VS_CODE_THEME_DESCRIPTOR" ]]; then
# Theme specifies a preferred 3rd-party extension/theme pair.
theme_name=$(jq -r '.name' "$VS_CODE_THEME_DESCRIPTOR")
local extension
extension=$(jq -r '.extension' "$VS_CODE_THEME")
extension=$(jq -r '.extension' "$VS_CODE_THEME_DESCRIPTOR")
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
# VS Code only discovers local color themes through an extension package.
install_generated_extension "$ext_base/omarchy-theme"
theme_name="Omarchy"
fi