Skip to content

Commit

Permalink
feat: support auto-saving a named session
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronr committed Oct 9, 2024
1 parent 9d02776 commit fa5e64b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lua/auto-session/autocmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ local function setup_dirchanged_autocmds(AutoSession)

AutoSession.AutoSaveSession()
AutoSession.run_cmds "pre_cwd_changed"
-- clear vim.v.this_session so it doesn't leak into another directory
vim.v.this_session = ""
end,
pattern = "global",
})
Expand Down
10 changes: 9 additions & 1 deletion lua/auto-session/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,16 @@ function AutoSession.AutoSaveSession()
end
end

local current_session = nil

-- If there's an existing session, use that name
if vim.v.this_session then
current_session = Lib.escaped_session_name_to_session_name(vim.fn.fnamemodify(vim.v.this_session, ":t"))
Lib.logger.debug("Using existing session name: " .. current_session)
end

-- Don't try to show a message as we're exiting
return AutoSession.SaveSession(nil, false)
return AutoSession.SaveSession(current_session, false)
end

---@private
Expand Down
6 changes: 6 additions & 0 deletions tests/allowed_dirs_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ describe("The allowed dirs config", function()
-- Change to a sub directory to see if it's allowed
vim.cmd "cd tests/test_files"

-- clear out any existing session
vim.v.this_session = ""

local session_path = TL.makeSessionPath(vim.fn.getcwd())
assert.equals(0, vim.fn.filereadable(session_path))

Expand All @@ -57,6 +60,9 @@ describe("The allowed dirs config", function()
vim.cmd("e " .. TL.test_file)
c.allowed_dirs = { vim.fn.getcwd() .. "/tests/symlink-test" }

-- clear out any existing session
vim.v.this_session = ""

vim.fn.system "ln -snf test_files tests/symlink-test"
vim.cmd "cd tests/symlink-test"

Expand Down

0 comments on commit fa5e64b

Please sign in to comment.