fix cwd after changing working directories
authorLukas Hägele <lukas.haegele93@web.de>
Sun, 29 Mar 2026 15:51:48 +0000 (17:51 +0200)
committerLukas Hägele <lukas.haegele93@web.de>
Sun, 29 Mar 2026 15:51:48 +0000 (17:51 +0200)
lua/snippets/vsplit.lua
plugin/sessionmanager.lua

index 7c68b2f3dbb4118e171d9de0f42a2835831562fc..59b59547911ad46e751b74793dad3cefe9f76f8e 100644 (file)
@@ -4,6 +4,7 @@ local M = {}
 M.reset = function(opts)
   opts = opts or {}
 
+  -- make sure that both windows exist
   if not (M.left_id and M.right_id) then
     -- remember window id of left pane for later
     M.left_id = vim.api.nvim_get_current_win()
@@ -19,15 +20,24 @@ M.reset = function(opts)
     M.right_id = vim.api.nvim_open_win(0, true, win_config)
   end
 
-  if opts.start_explorer then
-    local start_explorer = function(win_id, cwd)
+  -- set working directory and start file browser (for each window)
+  do
+    local set_cwd = function(win_id, cwd)
       vim.api.nvim_set_current_win(win_id)
-      vim.cmd.Explore(cwd)
+
+      if cwd then
+        vim.cmd("cd" ..cwd)
+      else
+        cwd = vim.fn.getcwd()
+      end
+
+      if opts.start_explorer then
+        vim.cmd.Explore(cwd)
+      end
     end
 
-    local cwd = vim.fn.getcwd()
-    start_explorer(M.left_id, cwd)
-    start_explorer(M.right_id, cwd)
+    set_cwd(M.left_id, opts.path)
+    set_cwd(M.right_id, opts.path)
   end
 end
 
index 18504ec3e8264759254618eb94ed3f686b314a12..f6f36e2bafc2755a879c76fd1053958f24f7a155 100644 (file)
@@ -43,18 +43,13 @@ local function session_picker(opts)
         -- close all buffers
         vim.cmd("bufdo bdelete")
 
+        -- determine new directory
         local selection = action_state.get_selected_entry()
         local entry = selection.value
 
-        -- change the current directory
-        vim.cmd("cd" ..entry.path)
-        while vim.fn.getcwd() ~= entry.path do
-          print("waiting...")
-        end
-
         -- split window
         local vsplit = require("snippets.vsplit")
-        vsplit.reset{ start_explorer = true }
+        vsplit.reset{ path = entry.path, start_explorer = true }
       end)
       return true
     end