Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/omarchy-theme-set
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
218 changes: 218 additions & 0 deletions bin/omarchy-theme-set-zen
Original file line number Diff line number Diff line change
@@ -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" <<EOF
/* Auto-generated by Omarchy. Do not edit manually. */
/* Theme: $theme_name */

:root {
--omarchy-bg: $bg;
--omarchy-fg: $fg;
--omarchy-accent: $accent;
--omarchy-surface: $surface;
--omarchy-surface-bright: $surface_bright;

--zen-accent-color: var(--omarchy-accent) !important;
--zen-border-color: var(--omarchy-surface) !important;
--zen-themed-toolbar-color: var(--omarchy-bg) !important;
--zen-colors-primary: var(--omarchy-accent) !important;
--zen-colors-secondary: var(--omarchy-surface) !important;
--zen-colors-tertiary: var(--omarchy-bg) !important;
--zen-dialog-background: var(--omarchy-bg) !important;
--zen-primary-color: var(--omarchy-accent) !important;
}

#TabsToolbar,
#vertical-tabs,
#tabbrowser-tabs,
#zen-sidebar-container,
#zen-appcontent-navbar-container,
#zen-main-app-wrapper,
#zen-sidebar-top-buttons,
#zen-sidebar-foot-buttons,
.zen-sidebar-panel-wrapper {
background-color: var(--omarchy-bg) !important;
color: var(--omarchy-fg) !important;
}

#vertical-tabs .toolbarbutton-1,
#zen-sidebar-top-buttons .toolbarbutton-1,
#zen-sidebar-foot-buttons .toolbarbutton-1,
#tabbrowser-tabs .tabbrowser-tab {
color: var(--omarchy-fg) !important;
}

.tabbrowser-tab .tab-background {
background-color: transparent !important;
}

.tabbrowser-tab[selected] .tab-background,
.tabbrowser-tab[visuallyselected] .tab-background,
#tabbrowser-tabs .tabbrowser-tab[selected] {
background-color: var(--omarchy-surface) !important;
border-radius: 8px !important;
}

.tabbrowser-tab .tab-label {
color: var(--omarchy-fg) !important;
opacity: 0.6;
}

.tabbrowser-tab[selected] .tab-label,
.tabbrowser-tab[visuallyselected] .tab-label {
color: var(--omarchy-fg) !important;
opacity: 1;
}

#nav-bar,
#PersonalToolbar {
background-color: var(--omarchy-bg) !important;
border: none !important;
}

#urlbar-background {
background-color: var(--omarchy-surface) !important;
border: 1px solid var(--omarchy-surface-bright) !important;
border-radius: 8px !important;
}

#urlbar:focus-within #urlbar-background {
border-color: var(--omarchy-accent) !important;
}

#urlbar .urlbar-input {
color: var(--omarchy-fg) !important;
}

.urlbarView-row[selected] .urlbarView-row-inner,
.urlbarView-row[selected] {
background-color: var(--omarchy-accent) !important;
color: var(--omarchy-bg) !important;
}

.urlbarView-row[selected] .urlbarView-title,
.urlbarView-row[selected] .urlbarView-url,
.urlbarView-row[selected] .urlbarView-secondary-action {
color: var(--omarchy-bg) !important;
}

browser,
#tabbrowser-tabpanels,
.browserStack {
background-color: var(--omarchy-bg) !important;
}

#zen-sidebar-splitter,
#appcontent-splitter,
.zen-sidebar-splitter {
background-color: var(--omarchy-surface) !important;
border: none !important;
min-width: 1px !important;
width: 1px !important;
}

#main-window {
border: 1px solid var(--omarchy-surface) !important;
outline: none !important;
}

#zen-appcontent-navbar-wrapper,
#titlebar {
background-color: var(--omarchy-bg) !important;
border: none !important;
outline: none !important;
box-shadow: none !important;
}
EOF
}

restart_zen() {
local command=""

if omarchy-cmd-present zen-bin; then
command="zen-bin"
elif [[ -x /opt/zen-browser-bin/zen-bin ]]; then
command="/opt/zen-browser-bin/zen-bin"
elif [[ -x /opt/zen-browser/zen ]]; then
command="/opt/zen-browser/zen"
fi

[[ -n $command ]] || return 0

if pgrep -x zen >/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