Skip to content

Commit

Permalink
Merge pull request #23 from gennaro-tedesco/delete_local_session
Browse files Browse the repository at this point in the history
Delete local session
  • Loading branch information
gennaro-tedesco authored May 16, 2023
2 parents 3f83336 + 372e506 commit 332fa39
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 14 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ Install `nvim-possession` with your favourite plugin manager (`fzf-lua` is requi
vim.keymap.set("n", "<leader>su", function()
possession.update()
end)
vim.keymap.set("n", "<leader>sd", function()
possession.delete()
end)
end,
}
```
Expand All @@ -58,6 +61,7 @@ Exposed interfaces
| possession.list() | list all the existing sessions with fzf-lua; preview shows files in session | `<CR>` load selected session<br>`<Ctrl-x>` delete selection session |
| possession.new() | prompt for name to create new session | session folder must alredy exist, return a message error otherwise |
| possession.update() | update current session (if new buffers are open) | do nothing if no session is loaded |
| possession.delete() | delete current session (without prompt) | do nothing if no session is loaded |

## 🛠 Usage and advanced configuration

Expand Down
36 changes: 25 additions & 11 deletions doc/possession.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
*possession.txt* For Neovim >= 0.8.0 Last change: 2023 February 19
*possession.txt* For Neovim >= 0.8.0 Last change: 2023 May 15

==============================================================================
Table of Contents *possession-table-of-contents*

- Installation and quickstart |possession-nil-installation-and-quickstart|
- Usage and advanced configuration|possession-nil-usage-and-advanced-configuration|
- Statusline |possession-nil-statusline|
- Feedback |possession-nil-feedback|
nvim-possessionNo-nonsense session managerYou are puzzled by neovim sessions and are not using them, are you? Start your
- Installation and quickstart |possession-installation-and-quickstart|
- Usage and advanced configuration|possession-usage-and-advanced-configuration|
- Statusline |possession-statusline|
- Feedback |possession-feedback|



nvim-possession





No-nonsense session managerYou are puzzled by neovim sessions and are not using them, are you? Start your
pos-sessions journey, fear no more!

This plugin is a no-nonsense session manager built on top of fzf-lua
Expand All @@ -17,15 +26,14 @@ sessions, create new ones, update and delete with a statusline component to
remind you of where you are. See for yourself:


INSTALLATION AND QUICKSTART *possession-nil-installation-and-quickstart*
INSTALLATION AND QUICKSTART *possession-installation-and-quickstart*

Install `nvim-possession` with your favourite plugin manager (`fzf-lua` is
required) and invoke `require("nvim-possession").setup({})`; in order to avoid
conflicts with your own keymaps we do not set any mappings but only expose the
interfaces, which means you would need to define them yourself. The suggested
quickstart configuration is, for instance


- with lazy.nvim <https://github.com/folke/lazy.nvim>

>lua
Expand All @@ -46,6 +54,9 @@ quickstart configuration is, for instance
vim.keymap.set("n", "<leader>su", function()
possession.update()
end)
vim.keymap.set("n", "<leader>sd", function()
possession.delete()
end)
end,
}
<
Expand All @@ -65,9 +76,12 @@ Exposed interfaces

possession.update() update current session (if new do nothing if no session is
buffers are open) loaded

possession.delete() delete current session (without do nothing if no session is
prompt) loaded
-------------------------------------------------------------------------------------

USAGE AND ADVANCED CONFIGURATION*possession-nil-usage-and-advanced-configuration*
USAGE AND ADVANCED CONFIGURATION *possession-usage-and-advanced-configuration*

As shown above the main use of the plugin is to show all existing sessions (say
via `<leader>sl`) and load the selected one upon `<CR>`. Once a session is
Expand Down Expand Up @@ -197,7 +211,7 @@ finders or set specific options. To do so you can use
<


STATUSLINE *possession-nil-statusline*
STATUSLINE *possession-statusline*

You can call `require("nvim-possession").status()` as component in your
statusline, for example with `lualine` you would have
Expand Down Expand Up @@ -227,7 +241,7 @@ the component automatically disappears or changes if you delete the current
session or switch to another one.


FEEDBACK *possession-nil-feedback*
FEEDBACK *possession-feedback*

If you find this plugin useful consider awarding it a , it is a great way to
give feedback! Otherwise, any additional suggestions or merge request is warmly
Expand Down
24 changes: 21 additions & 3 deletions lua/nvim-possession/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ M.setup = function(user_opts)

---delete selected session
---@param selected string
M.delete = function(selected)
M.delete_selected = function(selected)
local session = user_config.sessions.sessions_path .. selected[1]
local confirm = vim.fn.confirm("delete session?", "&Yes\n&No", 2)
if confirm == 1 then
Expand All @@ -88,7 +88,25 @@ M.setup = function(user_opts)
end
end
end
fzf.config.set_action_helpstr(M.delete, "delete-session")
fzf.config.set_action_helpstr(M.delete_selected, "delete-session")

--delete current active session
M.delete = function()
local cur_session = vim.g[user_config.sessions.sessions_variable]
if cur_session ~= nil then
local confirm = vim.fn.confirm("delete session " .. cur_session .. "?", "&Yes\n&No", 2)
if confirm == 1 then
local session_path = user_config.sessions.sessions_path .. cur_session
os.remove(session_path)
print("deleted " .. session_path)
if vim.g[user_config.sessions.sessions_variable] == vim.fs.basename(session_path) then
vim.g[user_config.sessions.sessions_variable] = nil
end
end
else
print("no active session")
end
end

---list all existing sessions and their files
---return fzf picker
Expand Down Expand Up @@ -116,7 +134,7 @@ M.setup = function(user_opts)
cwd = user_config.sessions.sessions_path,
actions = {
["default"] = M.load,
["ctrl-x"] = { M.delete, fzf.actions.resume },
["ctrl-x"] = { M.delete_selected, fzf.actions.resume },
},
})
end
Expand Down

0 comments on commit 332fa39

Please sign in to comment.