Merge pull request #23 from dedukun/save-last-bookmark

Save last bookmark
This commit is contained in:
Diogo Duarte
2024-08-18 17:11:49 +01:00
committed by GitHub
2 changed files with 26 additions and 2 deletions

View File

@@ -81,7 +81,8 @@ The following are the default configurations:
```lua ```lua
-- ~/.config/yazi/init.lua -- ~/.config/yazi/init.lua
require("bookmarks"):setup({ require("bookmarks"):setup({
save_last_directory = false, save_last_directory = false, -- DEPRECATED - will be removed in the future. Use `last_directory`
last_directory = { enable = false, persist = false },
persist = "none", persist = "none",
desc_format = "full", desc_format = "full",
notify = { notify = {
@@ -101,6 +102,15 @@ require("bookmarks"):setup({
When enabled, a new bookmark is automatically created in `'` which allows the user to jump back to When enabled, a new bookmark is automatically created in `'` which allows the user to jump back to
the last directory. the last directory.
***NOTE:*** This option is **DEPRECATED** and will be removed in the future in favor of `last_directory`.
### `last_directory`
When enabled, a new bookmark is automatically created in `'` which allows the user to jump back to
the last directory.
There's also the option to enable persistence to this automatic bookmark.
### `persist` ### `persist`
When enabled the bookmarks will persist, i.e. if you close and reopen Yazi they will still be When enabled the bookmarks will persist, i.e. if you close and reopen Yazi they will still be

View File

@@ -88,10 +88,19 @@ local _save_state = ya.sync(function(state, bookmarks)
ps.pub_to(0, "@bookmarks", save_state) ps.pub_to(0, "@bookmarks", save_state)
end) end)
local _save_last_directory = ya.sync(function(state) local _save_last_directory = ya.sync(function(state, persist)
if persist then
ps.sub_remote("@bookmarks-lastdir", function(body) state.curr_dir = body end)
end
ps.sub("cd", function() ps.sub("cd", function()
local file = _get_hovered_file() local file = _get_hovered_file()
state.last_dir = state.curr_dir state.last_dir = state.curr_dir
if persist and state.last_dir then
ps.pub_to(0, "@bookmarks-lastdir", state.last_dir)
end
state.curr_dir = { state.curr_dir = {
on = "'", on = "'",
desc = _generate_description(file), desc = _generate_description(file),
@@ -217,8 +226,13 @@ return {
return return
end end
-- TODO: DEPRECATED
if args.save_last_directory then if args.save_last_directory then
_save_last_directory() _save_last_directory()
elseif type(args.last_directory) == "table" then
if args.last_directory.enable then
_save_last_directory(args.last_directory.persist)
end
end end
if args.persist == "all" or args.persist == "vim" then if args.persist == "all" or args.persist == "vim" then