Skip to content

Commit

Permalink
Merge pull request #50 from gennaro-tedesco/fix_folder_path
Browse files Browse the repository at this point in the history
fix: do not loop through directories in the session path
  • Loading branch information
gennaro-tedesco authored Jan 31, 2025
2 parents d82907c + 9d8570a commit c6adf12
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lua/nvim-possession/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ M.setup = function(user_opts)
---list all existing sessions and their files
---return fzf picker
M.list = function()
local iter = vim.loop.fs_scandir(user_config.sessions.sessions_path)
local iter = vim.uv.fs_scandir(user_config.sessions.sessions_path)
if iter == nil then
print("session folder " .. user_config.sessions.sessions_path .. " does not exist")
return
end
local next = vim.loop.fs_scandir_next(iter)
local next = vim.uv.fs_scandir_next(iter)
if next == nil then
print("no saved sessions")
return
Expand Down
14 changes: 8 additions & 6 deletions lua/nvim-possession/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ end
---@return string|nil
M.session_in_cwd = function(sessions_path)
local session_dir, dir_pat = "", "^cd%s*"
for _, file in ipairs(vim.fn.readdir(sessions_path)) do
for line in io.lines(sessions_path .. file) do
if string.find(line, dir_pat) then
session_dir = vim.fs.normalize((line:gsub("cd%s*", "")))
if session_dir == vim.fn.getcwd() then
return file
for file, type in vim.fs.dir(sessions_path) do
if type == "file" then
for line in io.lines(sessions_path .. file) do
if string.find(line, dir_pat) then
session_dir = vim.uv.fs_realpath(vim.fs.normalize((line:gsub("cd%s*", ""))))
if session_dir == vim.fn.getcwd() then
return file
end
end
end
end
Expand Down

0 comments on commit c6adf12

Please sign in to comment.