Skip to content

Commit 7f7d396

Browse files
committed
fmt
1 parent 5e6762c commit 7f7d396

File tree

1 file changed

+40
-42
lines changed

1 file changed

+40
-42
lines changed

scripts/apply_theme.sh

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@ mkdir -p "$(dirname "$LOG_FILE")"
77
timestamp() { date +"%Y-%m-%d %H:%M:%S"; }
88

99
is_dark() {
10-
# Prefer AppleScript for reliable detection on modern macOS
11-
if osascript -e 'tell application "System Events" to tell appearance preferences to get dark mode' \
12-
2>/dev/null | grep -qi true; then
13-
return 0
14-
fi
15-
# Fallback to defaults key
16-
defaults read -g AppleInterfaceStyle 2>/dev/null | grep -qi "Dark"
10+
# Prefer AppleScript for reliable detection on modern macOS
11+
if osascript -e 'tell application "System Events" to tell appearance preferences to get dark mode' \
12+
2>/dev/null | grep -qi true; then
13+
return 0
14+
fi
15+
# Fallback to defaults key
16+
defaults read -g AppleInterfaceStyle 2>/dev/null | grep -qi "Dark"
1717
}
1818

1919
# Allow overriding theme with first argument: 'light' or 'dark'
2020
THEME_OVERRIDE=${1:-}
2121
case "$THEME_OVERRIDE" in
22-
light|dark)
23-
THEME="$THEME_OVERRIDE"
24-
;;
25-
*)
26-
if is_dark; then
27-
THEME="dark"
28-
else
29-
THEME="light"
30-
fi
31-
;;
22+
light | dark)
23+
THEME="$THEME_OVERRIDE"
24+
;;
25+
*)
26+
if is_dark; then
27+
THEME="dark"
28+
else
29+
THEME="light"
30+
fi
31+
;;
3232
esac
3333

3434
# Ensure PATH includes Homebrew bin for launchd context
@@ -41,51 +41,49 @@ KITTY_THEME_LINK="$HOME/.config/kitty/theme.conf"
4141

4242
# Ensure the kitty startup include points to the current theme
4343
if [ "$THEME" = "dark" ] && [ -f "$KITTY_THEME_DARK" ]; then
44-
ln -sf "$KITTY_THEME_DARK" "$KITTY_THEME_LINK"
44+
ln -sf "$KITTY_THEME_DARK" "$KITTY_THEME_LINK"
4545
elif [ "$THEME" = "light" ] && [ -f "$KITTY_THEME_LIGHT" ]; then
46-
ln -sf "$KITTY_THEME_LIGHT" "$KITTY_THEME_LINK"
46+
ln -sf "$KITTY_THEME_LIGHT" "$KITTY_THEME_LINK"
4747
fi
4848

4949
PREV_THEME=""
5050
if [ -f "$HOME/.theme" ]; then
51-
PREV_THEME=$(cat "$HOME/.theme" 2>/dev/null || true)
51+
PREV_THEME=$(cat "$HOME/.theme" 2>/dev/null || true)
5252
fi
5353

5454
if [ "$THEME" != "$PREV_THEME" ]; then
55-
echo "$(timestamp) Theme detected: $THEME" >>"$LOG_FILE"
56-
echo "$THEME" >"$HOME/.theme"
55+
echo "$(timestamp) Theme detected: $THEME" >>"$LOG_FILE"
56+
echo "$THEME" >"$HOME/.theme"
5757
fi
5858

5959
# Notify sketchybar if available
6060
if command -v sketchybar >/dev/null 2>&1; then
61-
if pgrep -x sketchybar >/dev/null 2>&1; then
62-
# Try to trigger a custom event first; fall back to reload
63-
sketchybar --trigger theme_change THEME="$THEME" >/dev/null 2>&1 || \
64-
sketchybar --reload >/dev/null 2>&1 || true
65-
fi
61+
if pgrep -x sketchybar >/dev/null 2>&1; then
62+
# Try to trigger a custom event first; fall back to reload
63+
sketchybar --trigger theme_change THEME="$THEME" >/dev/null 2>&1 ||
64+
sketchybar --reload >/dev/null 2>&1 || true
65+
fi
6666
fi
6767

6868
# Try to update kitty colors if remote control is available and theme files exist
6969
if command -v kitty >/dev/null 2>&1; then
70-
# Prefer fixed socket if configured to avoid controlling-terminal limitations
71-
if [ -S /tmp/kitty ]; then
72-
KITTYCTL=(kitty @ --to unix:/tmp/kitty)
73-
else
74-
KITTYCTL=(kitty @)
75-
fi
76-
# Apply to all running kitty windows regardless of change to enforce state
77-
if [ "$THEME" = "dark" ] && [ -f "$KITTY_THEME_DARK" ]; then
78-
"${KITTYCTL[@]}" set-colors --all --configured "$KITTY_THEME_DARK" >/dev/null 2>&1 || true
79-
elif [ "$THEME" = "light" ] && [ -f "$KITTY_THEME_LIGHT" ]; then
80-
"${KITTYCTL[@]}" set-colors --all --configured "$KITTY_THEME_LIGHT" >/dev/null 2>&1 || true
81-
fi
70+
# Prefer fixed socket if configured to avoid controlling-terminal limitations
71+
if [ -S /tmp/kitty ]; then
72+
KITTYCTL=(kitty @ --to unix:/tmp/kitty)
73+
else
74+
KITTYCTL=(kitty @)
75+
fi
76+
# Apply to all running kitty windows regardless of change to enforce state
77+
if [ "$THEME" = "dark" ] && [ -f "$KITTY_THEME_DARK" ]; then
78+
"${KITTYCTL[@]}" set-colors --all --configured "$KITTY_THEME_DARK" >/dev/null 2>&1 || true
79+
elif [ "$THEME" = "light" ] && [ -f "$KITTY_THEME_LIGHT" ]; then
80+
"${KITTYCTL[@]}" set-colors --all --configured "$KITTY_THEME_LIGHT" >/dev/null 2>&1 || true
81+
fi
8282
fi
8383

8484
# Optional user hook for further customization
8585
if [ -x "$HOME/scripts/on_theme_change.sh" ]; then
86-
"$HOME/scripts/on_theme_change.sh" "$THEME" >>"$LOG_FILE" 2>&1 || true
86+
"$HOME/scripts/on_theme_change.sh" "$THEME" >>"$LOG_FILE" 2>&1 || true
8787
fi
8888

8989
exit 0
90-
91-

0 commit comments

Comments
 (0)