diff options
| author | Pavel Egorov <[email protected]> | 2026-07-29 03:30:49 +0300 |
|---|---|---|
| committer | Pavel Egorov <[email protected]> | 2026-07-29 03:30:49 +0300 |
| commit | 71034d171fe80d305d766e15ba894de78062cc11 (patch) | |
| tree | 1b0209f66d466d506065250b76f139706e0c63d1 /.config/yay/hooks/install_log.lua | |
| parent | 6252009efa60f83094318a91be2d627709b1af8d (diff) | |
| download | dotfiles-71034d171fe80d305d766e15ba894de78062cc11.tar.gz dotfiles-71034d171fe80d305d766e15ba894de78062cc11.zip | |
Diffstat (limited to '.config/yay/hooks/install_log.lua')
| -rw-r--r-- | .config/yay/hooks/install_log.lua | 30 |
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 | |||
| 4 | local log_path = (os.getenv("XDG_STATE_HOME") or (os.getenv("HOME") .. "/.local/state")) .. "/yay/install.log" | ||
| 5 | local log_dir = log_path:match("^(.+)/[^/]+$") | ||
| 6 | |||
| 7 | yay.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 | }) | ||
