Track directory changes (cwd_change_handling)
mainBy default, AutoSession does not track cwd changes. When enabled via cwd_change_handling = true, changing the directory with :cd triggers a workflow:
- Pre-change: Saves the current session, clears all buffers (
%bw!), clears jumps, and runspre_cwd_changed_cmds. - Post-change: Restores the session for the new
cwdand runspost_cwd_changed_cmds.
This prevents buffer/jump bleeding between different project sessions.
opts = {
cwd_change_handling = true,
pre_cwd_changed_cmds = {
"tabdo NERDTreeClose", -- Close NERDTree before saving session
},
post_cwd_changed_cmds = {
function()
require("lualine").refresh() -- example refreshing the lualine status line _after_ the cwd changes
end,
},
}