Five scripts each hand-rolled colors.toml parsing plus their own alias/fallback cascade, and the tables had drifted: theme-osc grew a divergent color8/color9 chain, tmux and gnome carried private mode detection, and the preview tool duplicated the lot. The differences never mattered for shipped themes but were a standing bug factory for sparse user themes. omarchy-theme-color is now the single resolver. Its cascade is a verbatim port of the canonical theme-set-templates logic (semantic keys, legacy colorN aliases, derived shades, selection/cursor derivation, mode precedence), exposed as --all, --raw, or single-key lookup with fallback. Generated output is byte-identical across all 21 shipped themes on every surface: 17 template files, OSC byte stream, tmux and gsettings command logs, and previews. Sparse legacy themes now resolve the same palette everywhere instead of five slightly different ones. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
112 lines
2.8 KiB
Bash
Executable File
112 lines
2.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# omarchy:summary=Sync current Omarchy theme environment into tmux
|
|
# omarchy:hidden=true
|
|
|
|
CURRENT_THEME_PATH="$HOME/.local/state/omarchy/current/theme"
|
|
GUM_ENV="$CURRENT_THEME_PATH/gum_env.lua"
|
|
COLORS_TOML="$CURRENT_THEME_PATH/colors.toml"
|
|
|
|
if ! tmux list-sessions >/dev/null 2>&1; then
|
|
exit 0
|
|
fi
|
|
|
|
set_tmux_environment() {
|
|
local key="$1"
|
|
local value="$2"
|
|
local session
|
|
|
|
tmux set-environment -g "$key" "$value" 2>/dev/null || return 0
|
|
|
|
while IFS= read -r session; do
|
|
[[ -n $session ]] || continue
|
|
tmux set-environment -t "$session" "$key" "$value" 2>/dev/null || true
|
|
done < <(tmux list-sessions -F "#{session_id}" 2>/dev/null)
|
|
}
|
|
|
|
sync_theme_environment() {
|
|
local key value
|
|
|
|
[[ -f $GUM_ENV ]] || return
|
|
|
|
while IFS=$'\t' read -r key value; do
|
|
[[ -n $key && -n $value ]] || continue
|
|
set_tmux_environment "$key" "$value"
|
|
done < <(awk -F'"' '/hl\.env\("[A-Z0-9_]+", "[^"]+"\)/ { print $2 "\t" $4 }' "$GUM_ENV")
|
|
}
|
|
|
|
sync_colorfgbg() {
|
|
local colorfgbg="15;0"
|
|
|
|
# theme_color resolves mode from colors.toml, a legacy light.mode file, or
|
|
# background luminance, so a bare light check covers all theme styles.
|
|
if [[ $(theme_color mode) == "light" ]]; then
|
|
colorfgbg="0;15"
|
|
fi
|
|
|
|
set_tmux_environment COLORFGBG "$colorfgbg"
|
|
}
|
|
|
|
theme_osc_sequences() {
|
|
omarchy-theme-osc "$COLORS_TOML"
|
|
}
|
|
|
|
theme_color() {
|
|
omarchy-theme-color --file "$COLORS_TOML" "$@"
|
|
}
|
|
|
|
sync_tmux_window_style() {
|
|
local background foreground
|
|
|
|
[[ -f $COLORS_TOML ]] || return
|
|
|
|
foreground=$(theme_color foreground)
|
|
background=$(theme_color background)
|
|
|
|
[[ -n $foreground && -n $background ]] || return
|
|
|
|
tmux set-option -g window-style "fg=$foreground,bg=$background" 2>/dev/null || true
|
|
tmux set-option -g window-active-style "fg=$foreground,bg=$background" 2>/dev/null || true
|
|
}
|
|
|
|
sync_tmux_pane_colors() {
|
|
local pane_tty theme_osc
|
|
|
|
[[ -f $COLORS_TOML ]] || return
|
|
|
|
theme_osc=$(theme_osc_sequences)
|
|
[[ -n $theme_osc ]] || return
|
|
|
|
while IFS= read -r pane_tty; do
|
|
[[ $pane_tty == /dev/pts/* ]] || continue
|
|
printf '%b' "$theme_osc" >"$pane_tty" 2>/dev/null || true
|
|
done < <(tmux list-panes -a -F "#{pane_tty}" 2>/dev/null | sort -u)
|
|
}
|
|
|
|
signal_tmux_panes() {
|
|
local pane_tty tpgid
|
|
|
|
while IFS= read -r pane_tty; do
|
|
[[ $pane_tty == /dev/pts/* ]] || continue
|
|
tpgid=$(ps -o tpgid= -t "${pane_tty#/dev/}" 2>/dev/null | awk 'NF && $1 > 0 { print $1; exit }')
|
|
[[ -n $tpgid ]] || continue
|
|
kill -WINCH "-$tpgid" 2>/dev/null || true
|
|
done < <(tmux list-panes -a -F "#{pane_tty}" 2>/dev/null | sort -u)
|
|
}
|
|
|
|
refresh_tmux_clients() {
|
|
local client
|
|
|
|
while IFS= read -r client; do
|
|
[[ -n $client ]] || continue
|
|
tmux refresh-client -t "$client" 2>/dev/null || true
|
|
done < <(tmux list-clients -F "#{client_name}" 2>/dev/null)
|
|
}
|
|
|
|
sync_theme_environment
|
|
sync_colorfgbg
|
|
sync_tmux_window_style
|
|
sync_tmux_pane_colors
|
|
signal_tmux_panes
|
|
refresh_tmux_clients
|