diff --git a/bin/omarchy-theme-set b/bin/omarchy-theme-set index 8dafed8bfa..9da151180d 100755 --- a/bin/omarchy-theme-set +++ b/bin/omarchy-theme-set @@ -65,6 +65,7 @@ omarchy-restart-helix omarchy-theme-set-foot omarchy-theme-set-gnome omarchy-theme-set-browser +omarchy-theme-set-zen omarchy-theme-set-vscode omarchy-theme-set-obsidian omarchy-theme-set-keyboard diff --git a/bin/omarchy-theme-set-zen b/bin/omarchy-theme-set-zen new file mode 100755 index 0000000000..03545cefce --- /dev/null +++ b/bin/omarchy-theme-set-zen @@ -0,0 +1,218 @@ +#!/bin/bash + +# omarchy:summary=Sync Omarchy theme colors to Zen Browser chrome +# omarchy:hidden=true + +COLORS_TOML="$HOME/.config/omarchy/current/theme/colors.toml" +THEME_NAME_FILE="$HOME/.config/omarchy/current/theme.name" +ZEN_PROFILES_DIR="$HOME/.zen" +USER_CHROME_IMPORT='@import url("omarchy.css");' +USER_CHROME_PREF='user_pref("toolkit.legacyUserProfileCustomizations.stylesheets", true);' + +[[ -d $ZEN_PROFILES_DIR ]] || exit 0 +[[ -f $COLORS_TOML ]] || exit 0 + +parse_color() { + grep "^$1 " "$COLORS_TOML" | sed 's/.*= *"\(.*\)"/\1/' +} + +ensure_user_chrome_import() { + local user_chrome_css="$1" + local temp_file + + touch "$user_chrome_css" + + if ! grep -Fxq "$USER_CHROME_IMPORT" "$user_chrome_css"; then + temp_file=$(mktemp) + printf '%s\n' "$USER_CHROME_IMPORT" >"$temp_file" + cat "$user_chrome_css" >>"$temp_file" + mv "$temp_file" "$user_chrome_css" + fi +} + +ensure_user_chrome_pref() { + local user_js="$1" + + if [[ -f $user_js ]] && grep -q '^user_pref("toolkit\.legacyUserProfileCustomizations\.stylesheets",' "$user_js"; then + sed -i --follow-symlinks -E 's/^user_pref\("toolkit\.legacyUserProfileCustomizations\.stylesheets", .*/user_pref("toolkit.legacyUserProfileCustomizations.stylesheets", true);/' "$user_js" + else + printf '\n%s\n' "$USER_CHROME_PREF" >>"$user_js" + fi +} + +sync_profile_theme() { + local profile_dir="$1" + local chrome_dir="$profile_dir/chrome" + local user_chrome_css="$chrome_dir/userChrome.css" + local omarchy_css="$chrome_dir/omarchy.css" + local user_js="$profile_dir/user.js" + + mkdir -p "$chrome_dir" + ensure_user_chrome_import "$user_chrome_css" + ensure_user_chrome_pref "$user_js" + + cat >"$omarchy_css" </dev/null || pgrep -x zen-bin >/dev/null; then + pkill -x zen 2>/dev/null || true + pkill -x zen-bin 2>/dev/null || true + sleep 1 + "$command" &>/dev/null & + fi +} + +theme_name=$(cat "$THEME_NAME_FILE" 2>/dev/null || echo "unknown") +bg=$(parse_color "background") +fg=$(parse_color "foreground") +accent=$(parse_color "accent") +surface=$(parse_color "color0") +surface_bright=$(parse_color "color8") + +[[ -z $accent ]] && accent=$(parse_color "color4") +[[ -z $accent ]] && accent="#89b4fa" +[[ -z $surface ]] && surface=$bg +[[ -z $surface_bright ]] && surface_bright=$surface + +for profile_dir in "$ZEN_PROFILES_DIR"/*; do + [[ -d $profile_dir ]] || continue + [[ -f $profile_dir/prefs.js || -f $profile_dir/user.js ]] || continue + sync_profile_theme "$profile_dir" +done + +restart_zen