diff --git a/README.md b/README.md index 9f3e6db..6c55943 100644 --- a/README.md +++ b/README.md @@ -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. -
+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. @@ -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", + }, } }, ``` diff --git a/lua/kikao/config/aucommands.lua b/lua/kikao/config/aucommands.lua index 6a8a54d..f1c5d34 100644 --- a/lua/kikao/config/aucommands.lua +++ b/lua/kikao/config/aucommands.lua @@ -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 @@ -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 @@ -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, diff --git a/lua/kikao/config/init.lua b/lua/kikao/config/init.lua index 9ac1dce..3ce402d 100644 --- a/lua/kikao/config/init.lua +++ b/lua/kikao/config/init.lua @@ -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 diff --git a/lua/kikao/globals/init.lua b/lua/kikao/globals/init.lua index a9bb1f6..612a96a 100644 --- a/lua/kikao/globals/init.lua +++ b/lua/kikao/globals/init.lua @@ -1,5 +1,5 @@ local M = {} -M.VERSION = "1.0.2" +M.VERSION = "1.0.3" return M