Update fedora-niri-dms-setup.sh

This commit is contained in:
Jacob Schantli committed 2026-11-04 21:18:04 -07:00
1 parent 3283d80ab0
commit 6da00a9e8a
1 file changed
+82 -14
+82 -14
View File
@@ -254,23 +254,52 @@ if [[ ! -f "$NIRI_CFG" ]]; then
fi
fi
# Our settings live in their own file, included at the END of config.kdl.
# niri applies includes in order and a later bind overrides an earlier one, so
# these win over niri's defaults without editing them. Re-running the script
# simply rewrites this file.
NIRI_INC="$HOME/.config/niri/dms-setup.kdl"
cat > "$NIRI_INC" <<'EOF'
// Managed by fedora-niri-dms-setup; re-running the script overwrites this file.
// Put your own tweaks in config.kdl AFTER the include line to override these.
binds {
// Ptyxis instead of Alacritty
Mod+T hotkey-overlay-title="Open a Terminal: Ptyxis" { spawn "ptyxis"; }
// DMS replaces fuzzel and swaylock
Mod+D hotkey-overlay-title="App Launcher (DMS)" { spawn "dms" "ipc" "call" "spotlight" "toggle"; }
Super+Alt+L hotkey-overlay-title="Lock the Screen (DMS)" { spawn "dms" "ipc" "call" "lock" "lock"; }
// DMS panels
Mod+Alt+V hotkey-overlay-title="Clipboard History (DMS)" { spawn "dms" "ipc" "call" "clipboard" "toggle"; }
Mod+Alt+N hotkey-overlay-title="Notifications (DMS)" { spawn "dms" "ipc" "call" "notifications" "toggle"; }
Mod+Alt+C hotkey-overlay-title="Control Centre (DMS)" { spawn "dms" "ipc" "call" "control-center" "toggle"; }
Mod+Alt+S hotkey-overlay-title="DMS Settings" { spawn "dms" "ipc" "call" "settings" "toggle"; }
}
EOF
if [[ -f "$NIRI_CFG" ]]; then
[[ -f "$NIRI_CFG.orig" ]] || cp "$NIRI_CFG" "$NIRI_CFG.orig"
sed -i -E \
-e 's|^([[:space:]]*)spawn-at-startup "waybar"|\1// spawn-at-startup "waybar" // DMS provides the bar|' \
-e 's|spawn "alacritty"|spawn "ptyxis"|g' \
-e 's|spawn "fuzzel"|spawn "dms" "ipc" "call" "spotlight" "toggle"|g' \
-e 's|spawn "swaylock"|spawn "dms" "ipc" "call" "lock" "lock"|g' \
-e 's|Open a Terminal: alacritty|Open a Terminal: Ptyxis|' \
-e 's|Run an Application: fuzzel|Run an Application: DMS launcher|' \
-e 's|Lock the Screen: swaylock|Lock the Screen: DMS|' \
"$NIRI_CFG"
info "Waybar disabled, Super+T opens Ptyxis, launcher and lock keys use DMS"
info "Original config saved as $NIRI_CFG.orig"
if command -v niri >/dev/null && ! niri validate -c "$NIRI_CFG" >/dev/null 2>&1; then
warn "niri reports a config problem; restoring the original"
cp "$NIRI_CFG.orig" "$NIRI_CFG"
BEFORE=$(mktemp)
cp "$NIRI_CFG" "$BEFORE"
# The one edit an include can't do: stop Waybar autostarting (DMS is the bar).
sed -i -E 's|^([[:space:]]*)spawn-at-startup "waybar"|\1// spawn-at-startup "waybar" // DMS provides the bar|' "$NIRI_CFG"
if ! grep -qF 'include "dms-setup.kdl"' "$NIRI_CFG"; then
printf '\n// fedora-niri-dms-setup: DMS keybinds and Ptyxis (see dms-setup.kdl)\ninclude "dms-setup.kdl"\n' >> "$NIRI_CFG"
fi
if command -v niri >/dev/null && ! niri validate -c "$NIRI_CFG" >/dev/null 2>&1; then
warn "niri reports a config problem; reverting this run's changes"
cp "$BEFORE" "$NIRI_CFG"
else
info "Super+T opens Ptyxis; Super+D launcher, Super+Alt+L lock,"
info "Super+Alt+V clipboard, Super+Alt+N notifications, Super+Alt+C control centre, Super+Alt+S settings"
info "Original config saved as $NIRI_CFG.orig"
fi
rm -f "$BEFORE"
fi
# ---------- 7. Desktop essentials --------------------------------------------
@@ -440,6 +469,45 @@ if $WANT_EASYFX; then
info "Load Framework's speaker profile from their knowledge base after first login"
fi
# ---------- 10. Btrfs snapshots (snapper) -----------------------------------
# Snapshot the root filesystem before and after every dnf transaction, so a bad
# update can be undone from Btrfs Assistant. Runs last so the finished setup
# is the first baseline snapshot.
if [[ "$(findmnt -no FSTYPE /)" == "btrfs" ]]; then
step "Setting up Btrfs snapshots"
dnf_install snapper libdnf5-plugin-actions btrfs-assistant
if [[ ! -f /etc/snapper/configs/root ]]; then
sudo snapper -c root create-config /
fi
# Keep the 10 newest dnf snapshot pairs (5 marked important); no hourly ones.
sudo snapper -c root set-config \
NUMBER_LIMIT=10 NUMBER_LIMIT_IMPORTANT=5 \
TIMELINE_CREATE=no \
ALLOW_USERS="$USER" SYNC_ACL=yes
sudo systemctl enable --now snapper-cleanup.timer
# dnf5 hook: pre snapshot before each transaction, post snapshot after it.
sudo mkdir -p /etc/dnf/libdnf5-plugins/actions.d
sudo tee /etc/dnf/libdnf5-plugins/actions.d/snapper.actions >/dev/null <<'EOF'
# Managed by fedora-niri-dms-setup
# Take a snapper pre/post snapshot pair around every dnf transaction.
pre_transaction::::/usr/bin/sh -c echo\ "tmp.snapper_descr=$(ps\ -o\ command\ --no-headers\ -p\ '${pid}')"
pre_transaction::::/usr/bin/sh -c echo\ "tmp.snapper_pre=$(snapper\ -c\ root\ create\ -c\ number\ -t\ pre\ -p\ -d\ '${tmp.snapper_descr}')"
post_transaction::::/usr/bin/sh -c [\ -n\ "${tmp.snapper_pre}"\ ]\ &&\ snapper\ -c\ root\ create\ -c\ number\ -t\ post\ --pre-number\ "${tmp.snapper_pre}"\ -d\ "${tmp.snapper_descr}"\ ;\ echo\ tmp.snapper_pre\ ;\ echo\ tmp.snapper_descr
EOF
if ! sudo snapper -c root list --columns description 2>/dev/null | grep -q 'fedora-niri-dms-setup baseline'; then
sudo snapper -c root create -c important -d "fedora-niri-dms-setup baseline"
info "Baseline snapshot of the finished setup created"
fi
info "Every dnf install/update now takes a before/after snapshot."
info "Browse or restore them in Btrfs Assistant, or list with: snapper -c root list"
else
warn "Root filesystem isn't Btrfs; skipping snapshots"
fi
# ---------- done -------------------------------------------------------------
step "All done"