-- -- Session management for luakit -- By Silvio Rhatto -- Using https://luakit.github.io/docs/modules/session.html -- Inspired by https://github.com/IsoLinearCHiP/luakit-sessman -- -- Requirements local lfs = lfs local info = info local window = require "window" local modes = require "modes" local session = require "session" -- Base folder function basedir() return os.getenv("XDG_DATA_HOME") or os.getenv("HOME") .. "/.local/share" end -- The directory where sessions are stored local path = basedir() .. "/luakit/sessions/" if not lfs.attributes(path) then lfs.mkdir(path) end -- Commands modes.add_cmds({ { ":sessionload, :sload, :loadsession, :openssession", "Load a session", function (w, a) local file = path .. a.arg session.session_file = file session.restore(false) w:close_win() end}, { ":sessionsave, :ssave, :savesession", "Save a session", function (w, a) local file = path .. a.arg session.session_file = file session.save(file) msg.info("Saved session at " .. file) end}, { ":sessionremove, :srm, :removesession", "Remove a session", function (w, a) local file = path .. a.arg session.session_file = nil local deleted = session.load(true, file) end}, { ":sessions", "Session manager", function (w) local files = '' for file in lfs.dir(path) do if not (file == "." or file == "..") then files = files .. ' ' .. file end end w:notify("Available sessions:" .. files) end }, }) -- Bindings modes.add_binds("normal", { -- Quit and save session binding { "^q$", "Quit and save current session", function (w) session.save() for _, ww in pairs(window.bywidget) do ww:close_win(true) end end}, })