Skip to content

Commit

Permalink
Don't list the current session if we are on a session already (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeioth committed Jul 21, 2023
1 parent fbceeec commit 4883372
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Use the command `:SessionManager[!]` with one of the following arguments:

| Argument | Description |
| -------------------------- | -------------------------------------------------------------------------------------------- |
| `load_session` | Select and load session. |
| `load_session` | Select and load session. (Your current session won't appear on the list). |
| `load_last_session` | Will remove all buffers and `:source` the last saved session. |
| `load_current_dir_session` | Will remove all buffers and `:source` the last saved session file of the current dirtectory. |
| `save_current_session` | Works like `:mksession`, but saves/creates current directory as a session in `sessions_dir`. |
Expand Down
13 changes: 9 additions & 4 deletions lua/session_manager/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,20 @@ function utils.get_sessions()
end
table.sort(sessions, function(a, b) return a.timestamp > b.timestamp end)

-- If we are in a session already, show the penultimate saved session on top.
-- If we are not inside a session, show the latest saved session on top.
-- If we are in a session already, don't list the current session.
if utils.is_session then
local cwd = vim.loop.cwd()
if #sessions >= 2 and cwd and config.dir_to_session_filename(cwd).filename == sessions[1].filename then
sessions[1], sessions[2] = sessions[2], sessions[1]
local is_current_session = cwd and config.dir_to_session_filename(cwd).filename == sessions[1].filename
if is_current_session then
table.remove(sessions, 1)
end
end

-- If no sessions to list, send a notification.
if #sessions == 0 then
vim.notify('The only available session is your current session. Nothing to select from.', vim.log.levels.INFO)
end

return sessions
end

Expand Down

0 comments on commit 4883372

Please sign in to comment.