The script's jq fallback for .theme was hardcoded to "nord", which drifted from the lib/state-schema.nix default of "summer-night". With no state.json (or a blank one), nomarchy-theme-bg-next would look up backgrounds under themes/palettes/nord/ while the rest of the system treated summer-night as active — a quiet inconsistency that produced "no backgrounds found" errors on a system that hadn't yet written a theme to state. Matched it to the schema default. lib/state-schema.nix remains the single source of truth.
59 lines
1.6 KiB
Bash
Executable File
59 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
# Cycles through the background images available for the current theme.
|
|
# Declarative + Hybrid (instant swww) for Nomarchy NixOS.
|
|
|
|
STATE_DIR="$HOME/.config/nomarchy"
|
|
STATE_FILE="$STATE_DIR/state.json"
|
|
mkdir -p "$STATE_DIR"
|
|
[[ ! -f $STATE_FILE ]] && echo "{}" > "$STATE_FILE"
|
|
|
|
THEME_NAME=$(jq -r '.theme // "summer-night"' "$STATE_FILE")
|
|
|
|
# Resolve themes directory (Built-in from Nix store via Home Manager, or user extra)
|
|
if [ -d "$HOME/.config/nomarchy/themes/$THEME_NAME" ]; then
|
|
THEMES_DIR="$HOME/.config/nomarchy/themes"
|
|
else
|
|
THEMES_DIR="$HOME/.local/share/nomarchy/themes"
|
|
fi
|
|
|
|
BG_DIR="$THEMES_DIR/$THEME_NAME/backgrounds"
|
|
|
|
if [ ! -d "$BG_DIR" ]; then
|
|
notify-send "No background directory found for theme $THEME_NAME"
|
|
exit 1
|
|
fi
|
|
|
|
mapfile -t BACKGROUNDS < <(ls "$BG_DIR" | sort)
|
|
TOTAL=${#BACKGROUNDS[@]}
|
|
|
|
if (( TOTAL == 0 )); then
|
|
notify-send "No backgrounds found in $BG_DIR"
|
|
exit 1
|
|
fi
|
|
|
|
CURRENT_BG=$(jq -r '.wallpaper' "$STATE_FILE")
|
|
INDEX=-1
|
|
for i in "${!BACKGROUNDS[@]}"; do
|
|
if [[ "$BG_DIR/${BACKGROUNDS[$i]}" == "$CURRENT_BG" ]]; then
|
|
INDEX=$i
|
|
break
|
|
fi
|
|
done
|
|
|
|
NEXT_INDEX=$(((INDEX + 1) % TOTAL))
|
|
NEW_BG="$BG_DIR/${BACKGROUNDS[$NEXT_INDEX]}"
|
|
|
|
TMP_JSON=$(mktemp)
|
|
jq --arg wp "$NEW_BG" '.wallpaper = $wp' "$STATE_FILE" > "$TMP_JSON" && mv "$TMP_JSON" "$STATE_FILE"
|
|
|
|
# Instant feedback via swww
|
|
if pgrep -x swww-daemon >/dev/null; then
|
|
swww img "$NEW_BG" --transition-type outer --transition-pos 0.85,0.97 --transition-step 90
|
|
else
|
|
swww init && swww img "$NEW_BG"
|
|
fi
|
|
|
|
echo "Background set to $NEW_BG declaratively."
|