feat: add function save_last_and_quit

This commit is contained in:
MasouShizuka
2024-05-04 02:18:51 +08:00
parent 6694bc5bdb
commit 096765c489
2 changed files with 24 additions and 1 deletions

View File

@@ -55,6 +55,15 @@ run = "plugin projects --args=delete_all"
desc = "Delete all projects"
```
If you want to save the last project when exiting, map the default `quit` key to:
```toml
[[manager.prepend_keymap]]
on = [ "q" ]
run = "plugin projects --args=quit"
desc = "Save last project and exit the process"
```
---
Additionally there are configurations that can be done using the plugin's `setup` function in Yazi's `init.lua`, i.e. `~/.config/yazi/init.lua`.

View File

@@ -215,6 +215,15 @@ local delete_project = ya.sync(function(state, idx)
end
end)
local save_last_and_quit = ya.sync(function(state)
local projects = _get_projects()
projects.last = _get_current_project()
_save_state(projects)
ya.manager_emit("quit", {})
end)
return {
entry = function(_, args)
local action = args[1]
@@ -254,6 +263,11 @@ return {
return
end
if action == "quit" then
save_last_and_quit()
return
end
local projects = _get_projects()
if action == "load_last" then
@@ -266,7 +280,7 @@ return {
local list = projects.list
local selected_idx = ya.which({ cands = list })
local selected_idx = ya.which({ cands = list, silent = false })
if not selected_idx then
return
end