Skip to content

Commit

Permalink
Merge pull request #1 from mistweaverco/fix/session-creation
Browse files Browse the repository at this point in the history
fix(aucmd): only create session in root dir
  • Loading branch information
gorillamoe authored Sep 28, 2024
2 parents e51cbc9 + 0830bc8 commit 71cb758
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
19 changes: 7 additions & 12 deletions lua/kikao/config/aucommands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@ local M = {}
local save_session = false

local vim_leave_cb = function(session_file_path)
if save_session == false then
return
end
local sessiondir = vim.fn.fnamemodify(session_file_path, ":h")
vim.fn.mkdir(sessiondir, "p")
vim.cmd("mksession! " .. session_file_path)
end

local vim_enter_cb = function(data, project_dir_matchers, session_file_path, ps)
local is_oil = data.file:match("^oil://") ~= nil
local is_dir = vim.fn.isdirectory(data.file) == 1
if not is_dir and not is_oil then
return
end

local dir = is_oil and vim.fn.getcwd() or data.file
local vim_enter_cb = function(project_dir_matchers, session_file_path, ps)
local dir = vim.fn.getcwd()

for _, root in ipairs(project_dir_matchers) do
if vim.fn.isdirectory(dir .. ps .. root) == 1 then
Expand All @@ -29,8 +26,6 @@ local vim_enter_cb = function(data, project_dir_matchers, session_file_path, ps)
vim.cmd("source " .. session_file_path)
end
end

vim.cmd("bw " .. data.buf)
end

M.setup = function(config)
Expand All @@ -44,8 +39,8 @@ M.setup = function(config)
end

vim.api.nvim_create_autocmd("VimEnter", {
callback = function(data)
vim_enter_cb(data, config.project_dir_matchers, session_file_path, ps)
callback = function()
vim_enter_cb(config.project_dir_matchers, session_file_path, ps)
end,
group = augroup,
nested = true,
Expand Down
2 changes: 1 addition & 1 deletion lua/kikao/globals/init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local M = {}

M.VERSION = "1.0.0"
M.VERSION = "1.0.1"

return M

0 comments on commit 71cb758

Please sign in to comment.