From feffe662ee956e02733671357a5f80f97c1a2b5e Mon Sep 17 00:00:00 2001 From: Diogo Duarte Date: Wed, 14 Aug 2024 09:44:02 +0100 Subject: [PATCH 1/4] refactored last_directory configs + added persistence to last directory --- init.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 93e57bd..ba22263 100644 --- a/init.lua +++ b/init.lua @@ -88,10 +88,19 @@ local _save_state = ya.sync(function(state, bookmarks) ps.pub_to(0, "@bookmarks", save_state) 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() local file = _get_hovered_file() 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 = { on = "'", desc = _generate_description(file), @@ -217,8 +226,13 @@ return { return end + -- TODO: DEPRECATED if args.save_last_directory then _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 if args.persist == "all" or args.persist == "vim" then From a5a4ea1bd14e24dc572e1b140029202de128f088 Mon Sep 17 00:00:00 2001 From: Diogo Duarte Date: Wed, 14 Aug 2024 09:46:09 +0100 Subject: [PATCH 2/4] Update README --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 991d7e7..e87a983 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,8 @@ The following are the default configurations: ```lua -- ~/.config/yazi/init.lua require("bookmarks"):setup({ - save_last_directory = false, + save_last_directory = false, -- DEPRECATED - will be removed in the future + last_directory = { enable = false, persist = false }, persist = "none", desc_format = "full", 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 the last directory. +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` When enabled the bookmarks will persist, i.e. if you close and reopen Yazi they will still be From 944f7fd2b3627d9daf4273c9d16a9e3d2e0d09bf Mon Sep 17 00:00:00 2001 From: Diogo Duarte Date: Wed, 14 Aug 2024 09:51:58 +0100 Subject: [PATCH 3/4] update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e87a983..5b54d46 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ The following are the default configurations: ```lua -- ~/.config/yazi/init.lua require("bookmarks"):setup({ - save_last_directory = false, -- DEPRECATED - will be removed in the future + save_last_directory = false, -- DEPRECATED - will be removed in the future. Use `last_directory` last_directory = { enable = false, persist = false }, persist = "none", desc_format = "full", From 5039aaa7d3c436b99847a1dd54249ec35236d85b Mon Sep 17 00:00:00 2001 From: Diogo Duarte Date: Wed, 14 Aug 2024 09:56:02 +0100 Subject: [PATCH 4/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5b54d46..a1a259b 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ require("bookmarks"):setup({ When enabled, a new bookmark is automatically created in `'` which allows the user to jump back to the last directory. -This option is deprecated and will be removed in the future in favor of `last_directory`. +***NOTE:*** This option is **DEPRECATED** and will be removed in the future in favor of `last_directory`. ### `last_directory`