summaryrefslogtreecommitdiffstats
path: root/.config/yay/hooks/install_log.lua
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--.config/yay/hooks/install_log.lua30
1 files changed, 30 insertions, 0 deletions
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 @@
1-- Copypasted from https://github.com/Jguer/yay/blob/next/doc/examples/install_log.lua
2
3
4local log_path = (os.getenv("XDG_STATE_HOME") or (os.getenv("HOME") .. "/.local/state")) .. "/yay/install.log"
5local log_dir = log_path:match("^(.+)/[^/]+$")
6
7yay.create_autocmd("PostInstall", {
8 desc = "append every installed/upgraded package to a persistent log",
9 callback = function(event)
10 yay.log.info("install_log: writing to ", log_path)
11 os.execute("mkdir -p " .. log_dir)
12 local f, err = io.open(log_path, "a")
13 if not f then
14 yay.log.warn("install_log: cannot open log file: ", err)
15 return
16 end
17
18 local ts = os.date("%Y-%m-%dT%H:%M:%S")
19
20 for _, pkg in ipairs(event.data.packages) do
21 local upgrade = pkg.local_version ~= ""
22 local action = upgrade and "upgrade" or "install"
23 local version_change = upgrade and (pkg.local_version .. " -> " .. pkg.version) or pkg.version
24 f:write(string.format("%s %-9s %-7s %-14s %-12s %s\n",
25 ts, action, pkg.source, pkg.reason, pkg.name, version_change))
26 end
27
28 f:close()
29 end,
30})