ignore home directory in session manager and cleanup code
authorLukas Hägele <lukas.haegele93@web.de>
Sun, 29 Mar 2026 16:12:58 +0000 (18:12 +0200)
committerLukas Hägele <lukas.haegele93@web.de>
Sun, 29 Mar 2026 16:12:58 +0000 (18:12 +0200)
plugin/sessionmanager.lua

index f6f36e2bafc2755a879c76fd1053958f24f7a155..c12e5c1fa2b58924bf87945608237415dd5b4aa1 100644 (file)
@@ -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