From 587f714851ea21ece9ec0103036abbf7e4e958e9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lukas=20H=C3=A4gele?= Date: Sun, 29 Mar 2026 18:12:58 +0200 Subject: [PATCH] ignore home directory in session manager and cleanup code --- plugin/sessionmanager.lua | 69 +++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 29 deletions(-) diff --git a/plugin/sessionmanager.lua b/plugin/sessionmanager.lua index f6f36e2..c12e5c1 100644 --- a/plugin/sessionmanager.lua +++ b/plugin/sessionmanager.lua @@ -1,11 +1,28 @@ -local pickers = require "telescope.pickers" -local finders = require "telescope.finders" -local conf = require("telescope.config").values -local actions = require "telescope.actions" -local action_state = require "telescope.actions.state" - +local history_dir = vim.fn.stdpath("state") .."/sessionmanager/" +local history_file = history_dir .."history.lua" local history = {} +-- serialize and write to disk +local function serialize_to_disk() + local function serialize() + local str = "" + for _, entry in pairs(history) do + str = str .."Project { path = \"" ..entry.path .."\", timestamp = " ..(entry.timestamp or "nil") .." }\n" + end + + return str + end + + -- serialize history + local history_str = serialize() + + -- write to disk + vim.fn.mkdir(history_dir, "p") + local f = assert(io.open(history_file, "w")) + f:write(history_str) + f:close() +end + -- show session history in telescope local function session_picker(opts) opts = opts or require("telescope.themes").get_dropdown{} @@ -21,6 +38,12 @@ local function session_picker(opts) return (a.timestamp or 0) > (b.timestamp or 0) end) + local pickers = require "telescope.pickers" + local finders = require "telescope.finders" + local conf = require("telescope.config").values + local actions = require "telescope.actions" + local action_state = require "telescope.actions.state" + pickers.new(opts, { prompt_title = "session history", finder = finders.new_table { @@ -46,10 +69,15 @@ local function session_picker(opts) -- determine new directory local selection = action_state.get_selected_entry() local entry = selection.value + local path = entry.path + + -- update timestamp and serialize to disk + history[path].timestamp = os.time() + serialize_to_disk() -- split window local vsplit = require("snippets.vsplit") - vsplit.reset{ path = entry.path, start_explorer = true } + vsplit.reset{ path = path, start_explorer = true } end) return true end @@ -58,9 +86,6 @@ end -- read and update history file on disk do - local history_dir = vim.fn.stdpath("state") .."/sessionmanager/" - local history_file = history_dir .."history.lua" - -- read history from disk do function Project(entry) @@ -72,27 +97,13 @@ do -- add current directory to history do - local function serialize() - local str = "" - for _, entry in pairs(history) do - str = str .."Project { path = \"" ..entry.path .."\", timestamp = " ..(entry.timestamp or "nil") .." }\n" - end - - return str - end - local cwd = vim.fn.getcwd() - local entry = { path = cwd, timestamp = os.time() } - history[cwd] = entry - -- serialize history - local history_str = serialize() - - -- write to disk - vim.fn.mkdir(history_dir, "p") - local f = assert(io.open(history_file, "w")) - f:write(history_str) - f:close() + -- ignore home directory + if not ((cwd == vim.fn.expand("~")) or (cwd == vim.uv.os_homedir())) then + local entry = { path = cwd, timestamp = os.time() } + history[cwd] = entry + end end end -- 2.39.5