aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-09-17 12:20:39 +0200
committerDanilo M. <danix@danix.xyz>2026-09-17 12:20:39 +0200
commit9a479e198142a486413270c0e5dec8ed4405e023 (patch)
tree3d6a8e8282a44516af0d358b29a290e4467942d4
parent518b2969108ed3d728e562614c05e40400129240 (diff)
downloadconky-theme-udt-9a479e198142a486413270c0e5dec8ed4405e023.tar.gz
conky-theme-udt-9a479e198142a486413270c0e5dec8ed4405e023.zip
feat: add the disks and cache samplers
-rwxr-xr-xbin/cache-sample.sh33
-rwxr-xr-xbin/disks-sample.sh40
-rw-r--r--conky.conf.in2
3 files changed, 74 insertions, 1 deletions
diff --git a/bin/cache-sample.sh b/bin/cache-sample.sh
new file mode 100755
index 0000000..cac8911
--- /dev/null
+++ b/bin/cache-sample.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+# Sample ~/.cache sizes into a cache file, for widgets/cache.lua.
+#
+# du walks the tree and costs about 100ms warm, which is fine every 15 minutes
+# and unthinkable on a 2-second draw. The old conky config used the same
+# interval for the same reason.
+
+set -u
+
+CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/udt"
+CACHE="$CACHE_DIR/cachesize.txt"
+TARGET="${XDG_CACHE_HOME:-$HOME/.cache}"
+
+mkdir -p "$CACHE_DIR"
+
+TMP="$CACHE.tmp.$$"
+trap 'rm -f "$TMP"' EXIT
+umask 077
+
+# Total first, then the four largest children. `sort -h` compares human sizes
+# numerically; the Lua side converts them again because it needs the ratio to
+# the total, not just the order.
+{
+ du -sh "$TARGET" 2>/dev/null
+ du -sh "$TARGET"/* 2>/dev/null | sort -hr | head -4
+} > "$TMP"
+
+if [ ! -s "$TMP" ]; then
+ echo "cache-sample: du produced nothing" >&2
+ exit 1
+fi
+
+mv -f "$TMP" "$CACHE"
diff --git a/bin/disks-sample.sh b/bin/disks-sample.sh
new file mode 100755
index 0000000..83b8a62
--- /dev/null
+++ b/bin/disks-sample.sh
@@ -0,0 +1,40 @@
+#!/bin/bash
+# Sample filesystem usage into a cache file, for widgets/disks.lua.
+#
+# This exists so the draw hook never calls statfs on an NFS path. An
+# unreachable server blocks that call, and blocking the Cairo draw freezes the
+# whole dashboard; here it costs a stale cache and nothing else.
+#
+# One NFS mount per server: Library and Slackware are the same export on one
+# server, shared and backup_danix the same on another, so showing all four
+# printed every number twice.
+
+set -u
+
+CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/udt"
+CACHE="$CACHE_DIR/disks.txt"
+
+MOUNTS=(/ /home /data /mnt/nfs/Library /mnt/nfs/shared)
+
+mkdir -p "$CACHE_DIR"
+
+TMP="$CACHE.tmp.$$"
+trap 'rm -f "$TMP"' EXIT
+umask 077
+
+# /usr/bin/df by absolute path with -P -B1, deliberately:
+# - the user's shell aliases df to `df -h`, and an alias or a function would
+# hand the parser '1.6G' where it expects an integer
+# - -P is the POSIX format, one line per filesystem, mountpoint last
+# - -B1 is bytes, so the widget does the formatting and the parser never
+# has to interpret a suffix
+if ! /usr/bin/df -P -B1 "${MOUNTS[@]}" > "$TMP" 2>/dev/null; then
+ # A single unreachable mount must not discard the others: df still reports
+ # the ones it could stat, so keep the output if it has any data rows.
+ if [ "$(wc -l < "$TMP")" -lt 2 ]; then
+ echo "disks-sample: df produced nothing usable" >&2
+ exit 1
+ fi
+fi
+
+mv -f "$TMP" "$CACHE"
diff --git a/conky.conf.in b/conky.conf.in
index 9db8b0b..073fd80 100644
--- a/conky.conf.in
+++ b/conky.conf.in
@@ -51,4 +51,4 @@ conky.config = {
-- fires on schedule: verified with a probe config whose only text was an execi
-- producing no output. This is what refreshes the weather cache, and tying it
-- to conky means nothing fetches while the dashboard is down.
-conky.text = [[${execi 900 ~/.config/conky/bin/weather-fetch.sh}]]
+conky.text = [[${execi 900 ~/.config/conky/bin/weather-fetch.sh}${execi 60 ~/.config/conky/bin/disks-sample.sh}${execi 900 ~/.config/conky/bin/cache-sample.sh}]]