Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ The plugin saves the sessions in the specified folder (see [configuration](#conf
Use the command `:SessionManager[!]` with one of the following arguments:

| Argument | Description |
| -----------------------------| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `load_session` | Select and load session. (Your current session won't appear on the list). |
| ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `load_session` | Select and load session. (Your current session won't appear on the list by default, see configuration below). |
| `load_last_session` | Removes all buffers and tries to `:source` the last saved session. Returns `true` if the session was restored and `false` otherwise. |
| `load_current_dir_session` | Removes all buffers and tries to `:source` the last saved session of the current directory. Returns `true` if the session was restored and `false` otherwise. |
| `load_git_session` | When in a git repo, removes all buffers and tries to `:source` the last saved session of the git repo root directory. Returns `true` if the session was restored and `false` otherwise. |
Expand Down Expand Up @@ -48,6 +48,7 @@ require('session_manager').setup({
autosave_ignore_buftypes = {}, -- All buffers of these bufer types will be closed before the session is saved.
autosave_only_in_session = false, -- Always autosaves session. If true, only autosaves after a session is active.
max_path_length = 80, -- Shorten the display path if length exceeds this threshold. Use 0 if don't want to shorten the path at all.
load_include_current = false, -- The currently loaded session appears in the load_session UI.
})
```

Expand All @@ -71,7 +72,6 @@ autoload_mode = { config.AutoloadMode.CurrentDir, config.AutoloadMode.LastSessio

Would attempt to load the current directory session and then fallback to the last session.


## Autocommands

You can specify commands to be executed automatically after saving or loading a session using the following events:
Expand Down
1 change: 1 addition & 0 deletions lua/session_manager/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ config.defaults = {
autosave_ignore_buftypes = {},
autosave_only_in_session = false,
max_path_length = 80,
load_include_current = false,
}

setmetatable(config, { __index = config.defaults })
Expand Down
7 changes: 5 additions & 2 deletions lua/session_manager/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function session_manager.available_commands()
end)
end

--- Selects a session a loads it.
--- Selects a session and loads it.
---@param discard_current boolean: If `true`, do not check for unsaved buffers.
function session_manager.load_session(discard_current)
local sessions = utils.get_sessions()
Expand All @@ -35,7 +35,10 @@ function session_manager.load_session(discard_current)
format_item = function(item) return utils.shorten_path(item.dir) end,
}, function(item)
if item then
session_manager.autosave_session()
-- If re-loading the current session, do not save it before.
if item.filename ~= utils.active_session_filename then
session_manager.autosave_session()
end
utils.load_session(item.filename, discard_current)
end
end)
Expand Down
2 changes: 1 addition & 1 deletion lua/session_manager/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function utils.get_sessions(opts)
local sessions = {}
for _, session_filename in ipairs(scandir.scan_dir(tostring(config.sessions_dir), opts)) do
-- Add all but the active session to the list.
if session_filename ~= utils.active_session_filename then
if config.load_include_current or session_filename ~= utils.active_session_filename then
local dir = config.session_filename_to_dir(session_filename)
if dir:is_dir() then
table.insert(sessions, { timestamp = vim.fn.getftime(session_filename), filename = session_filename, dir = dir })
Expand Down
Loading