Skip to content

Commit da53c0f

Browse files
committed
Add Pi theme based on system theme
Based entirely on the work of @robzolkos in omacom#5711. That attempt was adapted to better fit the standard templating system while also adding color mixing for use in other themes.
1 parent ae6f2e7 commit da53c0f

8 files changed

Lines changed: 252 additions & 47 deletions

File tree

bin/omarchy-theme-set

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ post_theme_commands=(
173173
omarchy-restart-helix
174174
omarchy-theme-set-foot
175175
omarchy-theme-set-gnome
176+
omarchy-theme-set-pi
176177
omarchy-theme-set-browser
177178
omarchy-theme-set-vscode
178179
omarchy-theme-set-obsidian

bin/omarchy-theme-set-pi

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
3+
# omarchy:summary=Sync the generated Omarchy Pi theme
4+
# omarchy:args=[--activate]
5+
# omarchy:hidden=true
6+
7+
set -euo pipefail
8+
9+
CURRENT_THEME_PATH="$HOME/.config/omarchy/current/theme"
10+
PI_SOURCE_PATH="$CURRENT_THEME_PATH/pi.json"
11+
PI_AGENT_DIR="$HOME/.pi/agent"
12+
PI_THEME_DIR="$PI_AGENT_DIR/themes"
13+
PI_THEME_PATH="$PI_THEME_DIR/omarchy-system.json"
14+
PI_SETTINGS_PATH="$PI_AGENT_DIR/settings.json"
15+
PI_ACTIVATE=0
16+
17+
usage() {
18+
echo "Usage: omarchy-theme-set-pi [--activate]"
19+
}
20+
21+
for arg in "$@"; do
22+
case "$arg" in
23+
--activate)
24+
PI_ACTIVATE=1
25+
;;
26+
-h | --help)
27+
usage
28+
exit 0
29+
;;
30+
*)
31+
usage >&2
32+
exit 1
33+
;;
34+
esac
35+
done
36+
37+
if [[ ! -f $PI_SOURCE_PATH ]]; then
38+
if (( PI_ACTIVATE == 1 )); then
39+
echo "Pi theme source missing: $PI_SOURCE_PATH" >&2
40+
echo "Run omarchy-theme-refresh after selecting an Omarchy theme." >&2
41+
exit 1
42+
fi
43+
44+
exit 0
45+
fi
46+
47+
if (( PI_ACTIVATE == 0 )) && [[ ! -d $PI_AGENT_DIR ]]; then
48+
exit 0
49+
fi
50+
51+
write_setting_theme() {
52+
local tmp
53+
54+
mkdir -p "$PI_AGENT_DIR"
55+
56+
if [[ -f $PI_SETTINGS_PATH ]]; then
57+
tmp=$(mktemp "$PI_SETTINGS_PATH.XXXXXX")
58+
jq '.theme = "omarchy-system"' "$PI_SETTINGS_PATH" >"$tmp"
59+
mv "$tmp" "$PI_SETTINGS_PATH"
60+
else
61+
cat >"$PI_SETTINGS_PATH" <<EOF
62+
{
63+
"theme": "omarchy-system"
64+
}
65+
EOF
66+
fi
67+
}
68+
69+
mkdir -p "$PI_THEME_DIR"
70+
tmp=$(mktemp "$PI_THEME_PATH.XXXXXX")
71+
cp "$PI_SOURCE_PATH" "$tmp"
72+
mv "$tmp" "$PI_THEME_PATH"
73+
74+
if (( PI_ACTIVATE == 1 )); then
75+
write_setting_theme
76+
fi

default/pi/agent/extensions/omarchy-system-theme.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

default/themed/pi.json.tpl

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/earendil-works/pi/main/packages/coding-agent/src/modes/interactive/theme/theme-schema.json",
3+
"name": "omarchy-system",
4+
"vars": {
5+
"background": "{{ background }}",
6+
"foreground": "{{ foreground }}",
7+
"accent": "{{ accent }}",
8+
"selectionBackground": "{{ selection_background }}",
9+
"selectionForeground": "{{ selection_foreground }}",
10+
"selectedBackground": "{{ mix background accent 22% }}",
11+
"color0": "{{ color0 }}",
12+
"color1": "{{ color1 }}",
13+
"color2": "{{ color2 }}",
14+
"color3": "{{ color3 }}",
15+
"color4": "{{ color4 }}",
16+
"color5": "{{ color5 }}",
17+
"color6": "{{ color6 }}",
18+
"color7": "{{ color7 }}",
19+
"color8": "{{ color8 }}",
20+
"color9": "{{ color9 }}",
21+
"color10": "{{ color10 }}",
22+
"color11": "{{ color11 }}",
23+
"color12": "{{ color12 }}",
24+
"color13": "{{ color13 }}",
25+
"color14": "{{ color14 }}",
26+
"color15": "{{ color15 }}",
27+
"panel": "{{ mix background foreground 6% }}",
28+
"panelAlt": "{{ mix background foreground 10% }}",
29+
"panelPending": "{{ mix background accent 12% }}",
30+
"panelSuccess": "{{ mix background color2 12% }}",
31+
"panelError": "{{ mix background color1 12% }}",
32+
"border": "{{ mix background foreground 30% }}",
33+
"borderMuted": "{{ mix background foreground 20% }}",
34+
"mutedText": "{{ mix foreground background 34% }}",
35+
"dimText": "{{ mix foreground background 52% }}"
36+
},
37+
"colors": {
38+
"accent": "accent",
39+
"border": "border",
40+
"borderAccent": "accent",
41+
"borderMuted": "borderMuted",
42+
"success": "color2",
43+
"error": "color1",
44+
"warning": "color3",
45+
"muted": "mutedText",
46+
"dim": "dimText",
47+
"text": "foreground",
48+
"thinkingText": "dimText",
49+
"selectedBg": "selectedBackground",
50+
"userMessageBg": "panel",
51+
"userMessageText": "foreground",
52+
"customMessageBg": "panel",
53+
"customMessageText": "foreground",
54+
"customMessageLabel": "accent",
55+
"toolPendingBg": "panelPending",
56+
"toolSuccessBg": "panelSuccess",
57+
"toolErrorBg": "panelError",
58+
"toolTitle": "accent",
59+
"toolOutput": "foreground",
60+
"mdHeading": "color5",
61+
"mdLink": "accent",
62+
"mdLinkUrl": "color6",
63+
"mdCode": "color6",
64+
"mdCodeBlock": "foreground",
65+
"mdCodeBlockBorder": "borderMuted",
66+
"mdQuote": "mutedText",
67+
"mdQuoteBorder": "borderMuted",
68+
"mdHr": "borderMuted",
69+
"mdListBullet": "color5",
70+
"toolDiffAdded": "color2",
71+
"toolDiffRemoved": "color1",
72+
"toolDiffContext": "mutedText",
73+
"syntaxComment": "dimText",
74+
"syntaxKeyword": "color5",
75+
"syntaxFunction": "color4",
76+
"syntaxVariable": "accent",
77+
"syntaxString": "color2",
78+
"syntaxNumber": "color3",
79+
"syntaxType": "color4",
80+
"syntaxOperator": "color5",
81+
"syntaxPunctuation": "mutedText",
82+
"thinkingOff": "borderMuted",
83+
"thinkingMinimal": "accent",
84+
"thinkingLow": "color4",
85+
"thinkingMedium": "color5",
86+
"thinkingHigh": "color3",
87+
"thinkingXhigh": "color1",
88+
"bashMode": "color3"
89+
},
90+
"export": {
91+
"pageBg": "{{ background }}",
92+
"cardBg": "{{ mix background foreground 6% }}",
93+
"infoBg": "{{ mix background foreground 10% }}"
94+
}
95+
}

install/config/pi.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
mkdir -p ~/.pi/agent/extensions
2-
cp "$OMARCHY_PATH/default/pi/agent/extensions/omarchy-system-theme.ts" ~/.pi/agent/extensions/
1+
omarchy-theme-set-pi --activate

migrations/1778151386.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

migrations/1779242346.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
echo "Replace Pi's Omarchy light/dark extension with the generated omarchy-system theme"
2+
3+
rm -f "$HOME/.pi/agent/extensions/omarchy-system-theme.ts"
4+
omarchy-theme-refresh
5+
omarchy-theme-set-pi --activate

test/omarchy-cli-test.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set -euo pipefail
55
ROOT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)
66
CLI="$ROOT/bin/omarchy"
77
TMPDIR=""
8+
PI_TMPDIR=""
89

910
export PATH="$ROOT/bin:$PATH"
1011

@@ -33,6 +34,7 @@ assert_output_contains() {
3334

3435
cleanup() {
3536
[[ -n $TMPDIR && -d $TMPDIR ]] && rm -rf "$TMPDIR"
37+
[[ -n $PI_TMPDIR && -d $PI_TMPDIR ]] && rm -rf "$PI_TMPDIR"
3638
}
3739
trap cleanup EXIT
3840

@@ -188,6 +190,78 @@ pass "safe dispatch works for font list"
188190
"$CLI" font current >/dev/null
189191
pass "safe dispatch works for font current"
190192

193+
PI_TMPDIR=$(mktemp -d)
194+
NEXT_THEME="$PI_TMPDIR/.config/omarchy/current/next-theme"
195+
CURRENT_THEME="$PI_TMPDIR/.config/omarchy/current/theme"
196+
USER_THEMED="$PI_TMPDIR/.config/omarchy/themed"
197+
mkdir -p "$NEXT_THEME" "$CURRENT_THEME" "$USER_THEMED"
198+
199+
cat >"$NEXT_THEME/colors.toml" <<'EOF'
200+
accent = "#336699"
201+
cursor = "#ffffff"
202+
foreground = "#ffffff"
203+
background = "#000000"
204+
selection_foreground = "#000000"
205+
selection_background = "#808080"
206+
color0 = "#000000"
207+
color1 = "#ff0000"
208+
color2 = "#00ff00"
209+
color3 = "#ffff00"
210+
color4 = "#0000ff"
211+
color5 = "#ff00ff"
212+
color6 = "#00ffff"
213+
color7 = "#ffffff"
214+
color8 = "#111111"
215+
color9 = "#ff1111"
216+
color10 = "#11ff11"
217+
color11 = "#ffff11"
218+
color12 = "#1111ff"
219+
color13 = "#ff11ff"
220+
color14 = "#11ffff"
221+
color15 = "#eeeeee"
222+
EOF
223+
224+
cat >"$USER_THEMED/mix-test.txt.tpl" <<'EOF'
225+
mix={{ mix background foreground 50% }}
226+
strip={{ mix_strip background foreground 50% }}
227+
rgb={{ mix_rgb background foreground 50% }}
228+
EOF
229+
230+
OMARCHY_PATH="$ROOT" HOME="$PI_TMPDIR" "$ROOT/bin/omarchy-theme-set-templates"
231+
grep -qx 'mix=#808080' "$NEXT_THEME/mix-test.txt" || fail "theme template mix helper works"
232+
grep -qx 'strip=808080' "$NEXT_THEME/mix-test.txt" || fail "theme template mix_strip helper works"
233+
grep -qx 'rgb=128,128,128' "$NEXT_THEME/mix-test.txt" || fail "theme template mix_rgb helper works"
234+
pass "theme template color mix helpers work"
235+
236+
jq -e '.name == "omarchy-system" and .vars.panel == "#0f0f0f" and .vars.border == "#4d4d4d" and .colors.accent == "accent"' "$NEXT_THEME/pi.json" >/dev/null
237+
pass "pi theme template is generated from standard themed templates"
238+
cp "$NEXT_THEME/pi.json" "$CURRENT_THEME/pi.json"
239+
240+
echo '{"name":"omarchy-system","vars":{"custom":"yes"}}' >"$NEXT_THEME/pi.json"
241+
OMARCHY_PATH="$ROOT" HOME="$PI_TMPDIR" "$ROOT/bin/omarchy-theme-set-templates"
242+
jq -e '.name == "omarchy-system" and .vars.custom == "yes"' "$NEXT_THEME/pi.json" >/dev/null
243+
pass "theme-specific pi.json overrides the default template"
244+
245+
HOME="$PI_TMPDIR" "$ROOT/bin/omarchy-theme-set-pi"
246+
[[ ! -d $PI_TMPDIR/.pi ]] || fail "pi theme sync skips missing Pi agent when not activating"
247+
pass "pi theme sync skips missing Pi agent when not activating"
248+
249+
HOME="$PI_TMPDIR" "$ROOT/bin/omarchy-theme-set-pi" --activate
250+
[[ -f $PI_TMPDIR/.pi/agent/themes/omarchy-system.json ]] || fail "pi theme file is synced"
251+
pass "pi theme file is synced"
252+
[[ -f $PI_TMPDIR/.pi/agent/settings.json ]] || fail "pi settings file is generated"
253+
pass "pi settings file is generated"
254+
jq -e '.name == "omarchy-system" and .vars.panel == "#0f0f0f"' "$PI_TMPDIR/.pi/agent/themes/omarchy-system.json" >/dev/null
255+
pass "pi synced theme JSON is valid"
256+
jq -e '.theme == "omarchy-system"' "$PI_TMPDIR/.pi/agent/settings.json" >/dev/null
257+
pass "pi generated theme is activated"
258+
259+
jq '.model = "keep-me"' "$PI_TMPDIR/.pi/agent/settings.json" >"$PI_TMPDIR/settings.json.tmp"
260+
mv "$PI_TMPDIR/settings.json.tmp" "$PI_TMPDIR/.pi/agent/settings.json"
261+
HOME="$PI_TMPDIR" "$ROOT/bin/omarchy-theme-set-pi" --activate
262+
jq -e '.theme == "omarchy-system" and .model == "keep-me"' "$PI_TMPDIR/.pi/agent/settings.json" >/dev/null
263+
pass "pi theme activation preserves existing settings"
264+
191265
for binary in \
192266
omarchy-update \
193267
omarchy-theme-set \

0 commit comments

Comments
 (0)