Skip to content

Commit

Permalink
fix: #386 use right session name in auto create
Browse files Browse the repository at this point in the history
When auto-saving, if the session has been manually named use that
session name instead of the cwd session name. Fixes manually named
session not auto-saving on exit.
  • Loading branch information
cameronr committed Oct 14, 2024
1 parent 5a9d07b commit 59f3974
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lua/auto-session/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,16 @@ function AutoSession.AutoSaveSession()
return false
end

-- If there's a manually named session, use that on exit instead of one named for cwd
local current_session = nil

if AutoSession.manually_named_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

if not is_auto_create_enabled() then
local session_file_name = get_session_file_name()
local session_file_name = get_session_file_name(current_session)
if vim.fn.filereadable(AutoSession.get_root_dir() .. session_file_name) == 0 then
Lib.logger.debug "Create not enabled and no existing session, not creating session"
return false
Expand All @@ -314,13 +322,6 @@ function AutoSession.AutoSaveSession()
end
end

-- If there's a manually named session, use that on exit instead of one named for cwd
local current_session = nil
if AutoSession.manually_named_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(current_session, false)
end
Expand Down

0 comments on commit 59f3974

Please sign in to comment.