Skip to content

Commit

Permalink
fix(aucommands): skip session for deny list (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
gorillamoe authored Sep 29, 2024
1 parent a0ec27d commit f370ec3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ Kikao is swahili for "session".
It is a simple plugin that allows you to automatically save and
restore your session when you open and close neovim.

<p></p>
It basically saves the state of your editor when you close it and
restores it when you open it.

So you have your window layout and buffers just as you left them.

</div>

Expand Down Expand Up @@ -47,6 +50,11 @@ Via [lazy.nvim](https://github.com/folke/lazy.nvim):
-- The path to the session file
-- If not provided, the session file will be stored in {{PROJECT_DIR}}/.nvim/session.vim
session_file_path = nil,
-- Don't start or restore a session if the file is in the deny_on_path list
-- and you opened that file directly
deny_on_path = {
".git/COMMIT_EDITMSG",
},
}
},
```
Expand Down
12 changes: 8 additions & 4 deletions lua/kikao/config/aucommands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ local vim_leave_cb = function(session_file_path)
vim.cmd("mksession! " .. session_file_path)
end

local vim_enter_cb = function(data, project_dir_matchers, session_file_path, ps)
if data.file and vim.fn.filereadable(data.file) == 1 then
local vim_enter_cb = function(data, config, session_file_path, ps)
local file_path_rel = vim.fn.fnamemodify(data.file, ":~:.:p")
if data.file and vim.tbl_contains(config.deny_on_path, file_path_rel) then
return
end

local dir = vim.fn.getcwd()

for _, root in ipairs(project_dir_matchers) do
for _, root in ipairs(config.project_dir_matchers) do
if vim.fn.isdirectory(dir .. ps .. root) == 1 then
save_session = true
break
Expand All @@ -28,6 +29,9 @@ local vim_enter_cb = function(data, project_dir_matchers, session_file_path, ps)
if save_session then
if vim.fn.filereadable(session_file_path) == 1 then
vim.cmd("source " .. session_file_path)
if data.file then
vim.cmd("e " .. data.file)
end
end
end
end
Expand All @@ -44,7 +48,7 @@ M.setup = function(config)

vim.api.nvim_create_autocmd("VimEnter", {
callback = function(data)
vim_enter_cb(data, config.project_dir_matchers, session_file_path, ps)
vim_enter_cb(data, config, session_file_path, ps)
end,
group = augroup,
nested = true,
Expand Down
3 changes: 3 additions & 0 deletions lua/kikao/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ local M = {}
M.defaults = {
project_dir_matchers = { ".git", ".hg", ".bzr", ".svn" },
session_file_path = nil,
deny_on_path = {
".git/COMMIT_EDITMSG",
},
}

M.options = M.defaults
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.2"
M.VERSION = "1.0.3"

return M

0 comments on commit f370ec3

Please sign in to comment.