mirror of
https://github.com/Ascyii/projects.yazi.git
synced 2026-01-01 11:34:24 -05:00
feat: add function save_last_and_quit
This commit is contained in:
@@ -55,6 +55,15 @@ run = "plugin projects --args=delete_all"
|
|||||||
desc = "Delete all projects"
|
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`.
|
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`.
|
||||||
|
|||||||
16
init.lua
16
init.lua
@@ -215,6 +215,15 @@ local delete_project = ya.sync(function(state, idx)
|
|||||||
end
|
end
|
||||||
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 {
|
return {
|
||||||
entry = function(_, args)
|
entry = function(_, args)
|
||||||
local action = args[1]
|
local action = args[1]
|
||||||
@@ -254,6 +263,11 @@ return {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if action == "quit" then
|
||||||
|
save_last_and_quit()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local projects = _get_projects()
|
local projects = _get_projects()
|
||||||
|
|
||||||
if action == "load_last" then
|
if action == "load_last" then
|
||||||
@@ -266,7 +280,7 @@ return {
|
|||||||
|
|
||||||
local list = projects.list
|
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
|
if not selected_idx then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user