Dotfiles/desktopenvs/hyprlua/scripts/regen-beacon.sh

134 lines
5.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Regenerates hyprlua's mnotifd (from hyprdrive's beacon) and mnotifhist
# (from hyprdrive's transmitter-panel) — hyprlua's plain-themed notification
# daemon + history viewer, replacing dunst.
#
# Run BY HAND whenever hyprdrive's beacon/transmitter-panel change and you
# want those changes reflected here. Never wired into sysupdate.sh.
#
# What this does, per component:
# 1. rm -rf + cp -r the hyprdrive source tree in fresh (not an incremental
# patch — regenerating from scratch avoids drift bugs), dropping style/
# and any __pycache__.
# 2. Copies in the hand-maintained plain stylesheet from the matching
# desktopenvs/hyprlua/<name>-theme/ seed directory (never written to by
# this script — edit those by hand for a different plain look).
# 3. Flips the copied config.py's hologram/squiggle defaults to False (the
# real hyprdrive beacon/transmitter-panel default to True and are never
# touched by this script).
# 4. Runs one ordered rename table over every file's content AND over
# filenames: beacon -> mnotifd, transmitter-panel -> mnotifhist, plus
# the CamelCase class-name and UI-label variants actually present in
# the source (checked empirically, not guessed). This is what turns
# eu.abdelbaki.beacon.History1 into eu.abdelbaki.mnotifd.History1,
# beaconctl into mnotifdctl, ~/.config/beacon/... into
# ~/.config/mnotifd/..., etc. — all from the one table. Also rewrites
# the literal "hyprdrive" -> "hyprlua" (docstrings, and critically the
# D-Bus .service file's Exec= path, which otherwise still points at
# desktopenvs/hyprdrive/scripts/ after the beacon->mnotifd rename).
#
# The rename table intentionally does NOT touch the .tx-* / .close-btn CSS
# class names transmitter-panel/mnotifhist use — those prefixes don't
# contain "beacon" or "transmitter-panel" as substrings, so the mnotifhist
# plain stylesheet targets them unchanged. beacon's `.beacon-*` classes DO
# get renamed to `.mnotifd-*` (because "beacon" is a substring of each), so
# mnotifd's plain stylesheet is written against that post-rename vocabulary.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
HL="$(cd "$SCRIPT_DIR/.." && pwd)"
HD="$(cd "$HL/../hyprdrive" && pwd)"
# -- the rename table ---------------------------------------------------------
# Order matters: longest/most-specific compounds first, so e.g.
# "TransmitterPanelApp" resolves via its own rule before the bare
# "transmitter-panel" rule would otherwise mangle it mid-word.
rename_stream() {
sed \
-e 's/TransmitterPanelApp/MnotifhistApp/g' \
-e 's/TransmitterWindow/MnotifhistWindow/g' \
-e 's/BeaconWindow/MnotifdWindow/g' \
-e 's/BeaconApp/MnotifdApp/g' \
-e 's/transmitter-window/mnotifhist-window/g' \
-e 's/transmitter-panel/mnotifhist/g' \
-e 's/transmitterpanel/mnotifhist/g' \
-e 's/beacon/mnotifd/g' \
-e 's/Transmissions/Notifications/g' \
-e 's/hyprdrive/hyprlua/g'
}
rename_file_in_place() {
local f="$1" tmp
tmp="$(mktemp)"
rename_stream < "$f" > "$tmp"
mv "$tmp" "$f"
}
rename_tree_contents() {
local dir="$1" f
while IFS= read -r -d '' f; do
rename_file_in_place "$f"
done < <(find "$dir" -type f -print0)
}
flip_default() {
# Flip `"<key>": True` -> `"<key>": False` in a copied config.py's
# _DEFAULTS dict. No-op (silently) if the key isn't present.
local config_py="$1" key="$2"
sed -i "s/\"${key}\": *True/\"${key}\": False/" "$config_py"
}
# -- per-component regeneration ------------------------------------------------
regen_component() {
local src="$1" dst="$2" theme_dir="$3"
shift 3
local flip_keys=("$@")
rm -rf "$dst"
cp -r "$src" "$dst"
rm -rf "$dst/style" "$dst/__pycache__" "$dst/lib/__pycache__"
mkdir -p "$dst/style"
cp "$theme_dir/_colors.css" "$theme_dir/style.css" "$dst/style/"
local key
for key in "${flip_keys[@]}"; do
flip_default "$dst/config.py" "$key"
done
rename_tree_contents "$dst"
# rename any files/dirs whose *name* itself needs the substitution
# (deepest paths first, so renaming a parent dir doesn't orphan a path
# to a file inside it that find already queued)
local p renamed
while IFS= read -r -d '' p; do
renamed="$(dirname "$p")/$(basename "$p" | rename_stream)"
if [[ "$p" != "$renamed" ]]; then
mv "$p" "$renamed"
fi
done < <(find "$dst" -depth -print0)
return 0
}
regen_component "$HD/beacon" "$HL/mnotifd" "$HL/mnotifd-theme" hologram squiggle
regen_component "$HD/transmitter-panel" "$HL/mnotifhist" "$HL/mnotifhist-theme" hologram
# -- launcher / toggle scripts + CLI ------------------------------------------
regen_script() {
local src="$1" dst
dst="$SCRIPT_DIR/$(basename "$src" | rename_stream)"
rename_stream < "$src" > "$dst"
chmod +x "$dst"
}
regen_script "$HD/scripts/beacon-start.sh"
regen_script "$HD/scripts/beaconctl"
regen_script "$HD/scripts/transmitter-panel.sh"
regen_script "$HD/scripts/transmitter-panel-start.sh"
echo "Regenerated:"
echo " $HL/mnotifd/"
echo " $HL/mnotifhist/"
echo " $SCRIPT_DIR/mnotifd-start.sh, mnotifdctl, mnotifhist.sh, mnotifhist-start.sh"