diff --git a/bin/omarchy-theme-set b/bin/omarchy-theme-set index 8e0cb9e3..d987d97a 100755 --- a/bin/omarchy-theme-set +++ b/bin/omarchy-theme-set @@ -197,6 +197,7 @@ post_theme_commands=( omarchy-theme-set-tmux omarchy-theme-set-gnome omarchy-theme-set-pi + omarchy-theme-set-claude omarchy-theme-set-browser omarchy-theme-set-vscode omarchy-theme-set-obsidian diff --git a/bin/omarchy-theme-set-claude b/bin/omarchy-theme-set-claude new file mode 100755 index 00000000..06c2799c --- /dev/null +++ b/bin/omarchy-theme-set-claude @@ -0,0 +1,74 @@ +#!/bin/bash + +# omarchy:summary=Sync the generated Omarchy theme to Claude Code +# omarchy:args=[--activate] +# omarchy:hidden=true + +set -euo pipefail + +CLAUDE_SOURCE_PATH="$HOME/.local/state/omarchy/current/theme/claude.json" +CLAUDE_CONFIG_DIR="${CLAUDE_CONFIG_DIR:-$HOME/.claude}" +CLAUDE_THEME_PATH="$CLAUDE_CONFIG_DIR/themes/omarchy.json" +CLAUDE_SETTINGS_PATH="$CLAUDE_CONFIG_DIR/settings.json" +CLAUDE_ACTIVATE=0 + +usage() { + echo "Usage: omarchy-theme-set-claude [--activate]" +} + +for arg in "$@"; do + case "$arg" in + --activate) + CLAUDE_ACTIVATE=1 + ;; + -h | --help) + usage + exit 0 + ;; + *) + usage >&2 + exit 1 + ;; + esac +done + +if [[ ! -f $CLAUDE_SOURCE_PATH ]]; then + if (( CLAUDE_ACTIVATE == 1 )); then + echo "Claude Code theme source missing: $CLAUDE_SOURCE_PATH" >&2 + echo "Run omarchy-theme-refresh after selecting an Omarchy theme." >&2 + exit 1 + fi + + exit 0 +fi + +if (( CLAUDE_ACTIVATE == 0 )) && [[ ! -d $CLAUDE_CONFIG_DIR ]]; then + exit 0 +fi + +write_setting_theme() { + local tmp + + if [[ -f $CLAUDE_SETTINGS_PATH ]]; then + tmp=$(mktemp "$CLAUDE_SETTINGS_PATH.XXXXXX") + jq '.theme = "custom:omarchy"' "$CLAUDE_SETTINGS_PATH" >"$tmp" + mv "$tmp" "$CLAUDE_SETTINGS_PATH" + else + cat >"$CLAUDE_SETTINGS_PATH" </dev/null pass "pi theme activation preserves existing settings" +jq -e '.name == "Omarchy" and .base == "light" and .overrides.text == "#ffffff"' "$NEXT_THEME/claude.json" >/dev/null +pass "claude theme template is generated from standard themed templates" +cp "$NEXT_THEME/claude.json" "$CURRENT_THEME/claude.json" + +CLAUDE_TEST_CONFIG="$PI_TMPDIR/.claude-work" +mkdir -p "$CLAUDE_TEST_CONFIG" +HOME="$PI_TMPDIR" CLAUDE_CONFIG_DIR="$CLAUDE_TEST_CONFIG" "$ROOT/bin/omarchy-theme-set-claude" +[[ -f $CLAUDE_TEST_CONFIG/themes/omarchy.json ]] || fail "claude theme is synced to the configured directory" +[[ ! -d $PI_TMPDIR/.claude ]] || fail "claude theme sync avoids the default directory when configured" +pass "claude theme sync respects CLAUDE_CONFIG_DIR" + +echo '{"model":"keep-me"}' >"$CLAUDE_TEST_CONFIG/settings.json" +HOME="$PI_TMPDIR" CLAUDE_CONFIG_DIR="$CLAUDE_TEST_CONFIG" "$ROOT/bin/omarchy-theme-set-claude" --activate +jq -e '.theme == "custom:omarchy" and .model == "keep-me"' "$CLAUDE_TEST_CONFIG/settings.json" >/dev/null +pass "claude theme activation preserves configured settings" + THEME_TMPDIR=$(mktemp -d) OMARCHY_PATH="$ROOT" HOME="$THEME_TMPDIR" OMARCHY_THEME_HEADLESS=1 "$ROOT/bin/omarchy-theme-set" "Tokyo Night" background_path=$(readlink -f "$THEME_TMPDIR/.local/state/omarchy/current/background" 2>/dev/null || true)