diff options
| author | Danilo M. <danix@danix.xyz> | 2026-09-17 19:18:55 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-09-17 19:18:55 +0200 |
| commit | a906a204a8b9b6d8b46a938915737f6dc587e334 (patch) | |
| tree | 5004b01f94dfc231b4eeee69b83e203214d870e5 | |
| parent | 7b34edc8e7079a16755e342694173e9d194425d7 (diff) | |
| download | conky-theme-udt-a906a204a8b9b6d8b46a938915737f6dc587e334.tar.gz conky-theme-udt-a906a204a8b9b6d8b46a938915737f6dc587e334.zip | |
feat: sample the Slackware facts into a cache file
Conky's Lua has no lfs, so it cannot stat a file, and counting 2800 package
files per draw would be a directory walk every two seconds.
Writes epochs rather than formatted dates. The shell function this replaces
rebuilds a date from ls -l output with the year hardcoded, which breaks every
January and on any file older than six months.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
| -rwxr-xr-x | bin/slackware-sample.sh | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/bin/slackware-sample.sh b/bin/slackware-sample.sh new file mode 100755 index 0000000..3eb4818 --- /dev/null +++ b/bin/slackware-sample.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# Sample Slackware facts into a cache file, for widgets/slackware.lua. +# +# Conky's Lua has no lfs, so it cannot stat a file for an mtime, and counting +# 2800 package files every two seconds would be a directory walk per draw. +# Both belong here. + +set -u + +CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/udt" +CACHE="$CACHE_DIR/slackware.txt" + +umask 077 +mkdir -p "$CACHE_DIR" + +TMP="$CACHE.tmp.$$" +trap 'rm -f "$TMP"' EXIT + +VERSION=$(cat /etc/slackware-version 2>/dev/null || echo unknown) + +# The TRAILING SLASH is load-bearing. /var/log/packages is a symlink to +# /var/lib/pkgtools/packages, and `ls -1 /var/log/packages` lists the link +# itself: one entry. With the slash it lists the target's contents, which on +# this machine is some 2800 packages. Do not remove it as cosmetic. +PACKAGES=$(ls -1 /var/log/packages/ 2>/dev/null | wc -l) + +# Epochs, never formatted dates. The shell function this replaces rebuilds a +# date string from `ls -l` output with the year hardcoded, which breaks every +# January and on any file older than six months, when ls prints a year instead +# of a time and the field offsets shift. +CHANGELOG=$(stat -c %Y /var/lib/slackpkg/ChangeLog.txt 2>/dev/null || echo 0) + +# Filesystem birth time: the install date. Not every filesystem records it, +# and those that do not report 0, which the widget shows as '--'. +BIRTH=$(stat -c %W / 2>/dev/null || echo 0) + +KERNEL=$(uname -r) + +{ + echo "version $VERSION" + echo "packages $PACKAGES" + echo "changelog $CHANGELOG" + echo "birth $BIRTH" + echo "kernel $KERNEL" +} > "$TMP" + +mv -f "$TMP" "$CACHE" |
