Files
Nomarchy/themes/engine/scripts/nomarchy-theme-bg-set
Bernardo Magri dc3346bc55
Some checks failed
Check / eval-and-lint (push) Has been cancelled
feat: implement hybrid declarative state with automatic Nix sync
2026-05-31 20:09:12 +01:00

39 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
set -e
# Sets the specified image as the current background.
# Updates state.json so the choice survives the next rebuild — without
# that write, themes/engine/files.nix re-resolves the wallpaper from
# `nomarchy.wallpaper` on the next home-manager switch and silently
# falls back to the active theme's default background, undoing the
# user's pick.
if [[ -z $1 ]]; then
echo "Usage: nomarchy-theme-bg-set <path-to-image>" >&2
exit 1
fi
BACKGROUND="$1"
if [[ ! -f "$BACKGROUND" ]]; then
echo "Background image not found: $BACKGROUND" >&2
exit 1
fi
STATE_DIR="$HOME/.config/nomarchy"
STATE_FILE="$STATE_DIR/state.json"
CURRENT_BACKGROUND_LINK="$STATE_DIR/current/background"
mkdir -p "$STATE_DIR"
[[ ! -f $STATE_FILE ]] && echo "{}" > "$STATE_FILE"
# Persist the choice for the next rebuild.
nomarchy-state-write wallpaper "$BACKGROUND"
# Create symlink to the new background
ln -nsf "$BACKGROUND" "$CURRENT_BACKGROUND_LINK"
# Kill existing swaybg and start new one
pkill -x swaybg
setsid uwsm-app -- swaybg -i "$CURRENT_BACKGROUND_LINK" -m fill >/dev/null 2>&1 &