From 71034d171fe80d305d766e15ba894de78062cc11 Mon Sep 17 00:00:00 2001 From: Pavel Egorov Date: Wed, 29 Jul 2026 03:30:49 +0300 Subject: [yay] add hooks --- .config/yay/hooks/install_log.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .config/yay/hooks/install_log.lua (limited to '.config/yay/hooks/install_log.lua') diff --git a/.config/yay/hooks/install_log.lua b/.config/yay/hooks/install_log.lua new file mode 100644 index 0000000..e07183e --- /dev/null +++ b/.config/yay/hooks/install_log.lua @@ -0,0 +1,30 @@ +-- Copypasted from https://github.com/Jguer/yay/blob/next/doc/examples/install_log.lua + + +local log_path = (os.getenv("XDG_STATE_HOME") or (os.getenv("HOME") .. "/.local/state")) .. "/yay/install.log" +local log_dir = log_path:match("^(.+)/[^/]+$") + +yay.create_autocmd("PostInstall", { + desc = "append every installed/upgraded package to a persistent log", + callback = function(event) + yay.log.info("install_log: writing to ", log_path) + os.execute("mkdir -p " .. log_dir) + local f, err = io.open(log_path, "a") + if not f then + yay.log.warn("install_log: cannot open log file: ", err) + return + end + + local ts = os.date("%Y-%m-%dT%H:%M:%S") + + for _, pkg in ipairs(event.data.packages) do + local upgrade = pkg.local_version ~= "" + local action = upgrade and "upgrade" or "install" + local version_change = upgrade and (pkg.local_version .. " -> " .. pkg.version) or pkg.version + f:write(string.format("%s %-9s %-7s %-14s %-12s %s\n", + ts, action, pkg.source, pkg.reason, pkg.name, version_change)) + end + + f:close() + end, +}) -- cgit v1.3