From 54eacef87b906835f9778d9c4b02128398bf88d0 Mon Sep 17 00:00:00 2001 From: sommerfeld Date: Wed, 13 May 2026 13:43:35 +0100 Subject: feat(lostfiles): weekly unowned-files refresh + waybar reminder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Wiring (mirrors arch-audit, with weekly cadence and Nice=19/idle I/O): lostfiles.timer (weekly, Persistent=true, RandomizedDelaySec=1h) → lostfiles.service → /run/lostfiles.txt (default mode — strict produces too many false positives for a passive reminder) → custom/lostfiles waybar module (interval 600s) → mako 'normal' once/7d while count > 0 → on-click: `ghostty -e nvim -R /run/lostfiles.txt` Default mode (no `strict` argument) is intentional: it already filters the package's curated false-positive list at /etc/lostfiles.conf, which is what we want for a low-noise weekly nudge. Switching to `strict` is a one-line change in lostfiles.service if signal-vs-noise tilts later. --- dot_config/waybar/executable_lostfiles-status.sh | 48 ++++++++++++++++++++++++ etc/systemd/system/lostfiles.service | 10 +++++ etc/systemd/system/lostfiles.timer | 11 ++++++ 3 files changed, 69 insertions(+) create mode 100755 dot_config/waybar/executable_lostfiles-status.sh create mode 100644 etc/systemd/system/lostfiles.service create mode 100644 etc/systemd/system/lostfiles.timer diff --git a/dot_config/waybar/executable_lostfiles-status.sh b/dot_config/waybar/executable_lostfiles-status.sh new file mode 100755 index 0000000..f5f1099 --- /dev/null +++ b/dot_config/waybar/executable_lostfiles-status.sh @@ -0,0 +1,48 @@ +#!/bin/sh +# Waybar custom/lostfiles: shows count of filesystem entries not owned +# by any pacman package (and not on lostfiles' built-in safe-list). +# Source of truth is /run/lostfiles.txt, refreshed weekly by +# lostfiles.timer (system scope). Hidden when zero or report missing. +# +# Mako throttled to once per 7d via a stamp in $XDG_RUNTIME_DIR — the +# report itself only changes weekly so anything more frequent would +# re-fire on the same data. + +set -eu + +REPORT=/run/lostfiles.txt +STATE=${XDG_RUNTIME_DIR:-/tmp}/waybar-lostfiles-notified + +emit_empty() { + printf '{"text":"","class":"fresh","tooltip":""}\n' + exit 0 +} + +[ -r "$REPORT" ] || emit_empty + +count=$(grep -c . "$REPORT" 2>/dev/null || :) +case "$count" in '' | *[!0-9]*) count=0 ;; esac + +[ "$count" -eq 0 ] && emit_empty + +text="lost ${count}" +tooltip="${count} unowned file(s) under tracked dirs — click to review in \`nvim -R\`" +printf '{"text":"%s","class":"warn","tooltip":"%s"}\n' "$text" "$tooltip" + +now=$(date +%s) +last_notified=0 +if [ -f "$STATE" ]; then + last_notified=$(cat "$STATE" 2>/dev/null || printf 0) + case "$last_notified" in '' | *[!0-9]*) last_notified=0 ;; esac +fi + +if [ $((now - last_notified)) -ge 604800 ] && + command -v notify-send >/dev/null 2>&1; then + notify-send \ + --app-name=lostfiles \ + --urgency=normal \ + --icon=folder-documents \ + "Unowned files detected" \ + "${count} entries under tracked dirs aren't owned by any package. Review at your leisure." + printf '%s\n' "$now" >"$STATE" +fi diff --git a/etc/systemd/system/lostfiles.service b/etc/systemd/system/lostfiles.service new file mode 100644 index 0000000..4d94a18 --- /dev/null +++ b/etc/systemd/system/lostfiles.service @@ -0,0 +1,10 @@ +[Unit] +Description=Refresh lostfiles report at /run/lostfiles.txt +Documentation=man:lostfiles(1) +ConditionPathExists=/usr/bin/lostfiles + +[Service] +Type=oneshot +Nice=19 +IOSchedulingClass=idle +ExecStart=/bin/sh -c '/usr/bin/lostfiles >/run/lostfiles.txt.tmp && mv /run/lostfiles.txt.tmp /run/lostfiles.txt' diff --git a/etc/systemd/system/lostfiles.timer b/etc/systemd/system/lostfiles.timer new file mode 100644 index 0000000..e99d4be --- /dev/null +++ b/etc/systemd/system/lostfiles.timer @@ -0,0 +1,11 @@ +[Unit] +Description=Weekly lostfiles report refresh + +[Timer] +OnCalendar=weekly +AccuracySec=12h +Persistent=true +RandomizedDelaySec=1h + +[Install] +WantedBy=timers.target -- cgit v1.3.1