From b8722e83c456adba0e323453a73d984558f5b016 Mon Sep 17 00:00:00 2001 From: Diogo Duarte Date: Sun, 31 Mar 2024 15:28:55 +0100 Subject: [PATCH 01/10] started working of having '' go to last dir --- init.lua | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index 992531b..30c5dbc 100644 --- a/init.lua +++ b/init.lua @@ -43,7 +43,15 @@ local save_bookmark = ya.sync(function(state, idx) end end) -local all_bookmarks = ya.sync(function(state) return state.bookmarks or {} end) +local all_bookmarks = ya.sync(function(state, append_last_dir) + bookmarks = state.bookmarks or {} + + if append_last_dir and state.last_dir then + table.insert(bookmarks, state.last_dir) + end + + return bookmarks +end) local delete_bookmark = ya.sync(function(state, idx) if state.notify and state.notify.enable then @@ -72,6 +80,18 @@ local delete_all_bookmarks = ya.sync(function(state) end end) +local _save_last_dir = ya.sync(function(state) + ps.sub("cd", function() + local folder = Folder:by_kind(Folder.CURRENT) + state.last_dir = state.curr_dir + state.curr_dir = { + on = "'", + desc = tostring(folder.cwd), + cursor = folder.cursor, + } + end) +end) + return { entry = function(_, args) local action = args[1] @@ -91,7 +111,7 @@ return { return delete_all_bookmarks() end - local bookmarks = all_bookmarks() + local bookmarks = all_bookmarks(action == "jump") local selected = #bookmarks > 0 and ya.which { cands = bookmarks } if not selected then return @@ -110,6 +130,8 @@ return { return end + _save_last_dir() + state.notify = { enable = false, timeout = 1, From 13bd26ea58d9fdcced218f39bb9ecb56736f171a Mon Sep 17 00:00:00 2001 From: Diogo Duarte Date: Sun, 31 Mar 2024 16:33:45 +0100 Subject: [PATCH 02/10] Updating state.curr_dir on hover + added initial state to it --- init.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/init.lua b/init.lua index 30c5dbc..bc80038 100644 --- a/init.lua +++ b/init.lua @@ -81,6 +81,12 @@ local delete_all_bookmarks = ya.sync(function(state) end) local _save_last_dir = ya.sync(function(state) + state.curr_dir = { + on = "'", + desc = "~", -- FIX This might not be true, i.e. the user entry point might not be the home dir + cursor = 0, + } + ps.sub("cd", function() local folder = Folder:by_kind(Folder.CURRENT) state.last_dir = state.curr_dir @@ -90,6 +96,11 @@ local _save_last_dir = ya.sync(function(state) cursor = folder.cursor, } end) + + ps.sub("hover", function() + local folder = Folder:by_kind(Folder.CURRENT) + state.curr_dir.cursor = folder.cursor + end) end) return { From 950068ec64cff9569fecaac80155e563ecc710be Mon Sep 17 00:00:00 2001 From: Diogo Duarte Date: Sun, 31 Mar 2024 16:51:53 +0100 Subject: [PATCH 03/10] shallow copy when getting all bookmarks --- init.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index bc80038..4093768 100644 --- a/init.lua +++ b/init.lua @@ -44,7 +44,11 @@ local save_bookmark = ya.sync(function(state, idx) end) local all_bookmarks = ya.sync(function(state, append_last_dir) - bookmarks = state.bookmarks or {} + local bookmarks = {} + + for _, value in pairs(state.bookmarks) do + table.insert(bookmarks, value) + end if append_last_dir and state.last_dir then table.insert(bookmarks, state.last_dir) From 9f3b4a5c4a00c0ce50fc1ddeeb12772687bbc822 Mon Sep 17 00:00:00 2001 From: Diogo Duarte Date: Sun, 31 Mar 2024 17:23:30 +0100 Subject: [PATCH 04/10] Add argument for enabling save_last_directory --- init.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/init.lua b/init.lua index 4093768..a146efc 100644 --- a/init.lua +++ b/init.lua @@ -46,8 +46,10 @@ end) local all_bookmarks = ya.sync(function(state, append_last_dir) local bookmarks = {} - for _, value in pairs(state.bookmarks) do - table.insert(bookmarks, value) + if state.bookmarks then + for _, value in pairs(state.bookmarks) do + table.insert(bookmarks, value) + end end if append_last_dir and state.last_dir then @@ -84,7 +86,7 @@ local delete_all_bookmarks = ya.sync(function(state) end end) -local _save_last_dir = ya.sync(function(state) +local _save_last_directory = ya.sync(function(state) state.curr_dir = { on = "'", desc = "~", -- FIX This might not be true, i.e. the user entry point might not be the home dir @@ -145,7 +147,9 @@ return { return end - _save_last_dir() + if args.save_last_directory then + _save_last_directory() + end state.notify = { enable = false, From 951aec64306aa0379c8a4630be2584109bb1bf35 Mon Sep 17 00:00:00 2001 From: Diogo Duarte Date: Sun, 31 Mar 2024 18:12:15 +0100 Subject: [PATCH 05/10] Temporary fix to mitigate the issue no being able to get CWD in setup --- init.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/init.lua b/init.lua index a146efc..9c51070 100644 --- a/init.lua +++ b/init.lua @@ -106,6 +106,7 @@ local _save_last_directory = ya.sync(function(state) ps.sub("hover", function() local folder = Folder:by_kind(Folder.CURRENT) state.curr_dir.cursor = folder.cursor + state.curr_dir.desc = tostring(folder.cwd) -- FIX Not needed when the we are able to get the CWD in the setup end) end) From 9904a48efa5345409bf42dda47553987fa04391e Mon Sep 17 00:00:00 2001 From: Diogo Duarte Date: Sun, 31 Mar 2024 18:43:26 +0100 Subject: [PATCH 06/10] update README --- README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f545ab0..f143bea 100644 --- a/README.md +++ b/README.md @@ -45,12 +45,13 @@ desc = "Delete all bookmarks" --- -Additionally you can enable notifications by calling 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`. The following are the default configurations: ```lua -- ~/.config/yazi/init.lua require("bookmarks"):setup({ + save_last_directory = false, notify = { enable = false, timeout = 1, @@ -63,4 +64,17 @@ require("bookmarks"):setup({ }) ``` +### `save_last_directory` + +When enabled, a new bookmark is automatically created in `''` which allows the user to jump back to +the last directory. + +### Notify + +When enabled, notifications will be shown when the user creates a new bookmark and deletes one or +all saved bookmarks. + +By default the notification as a 1 second timeout that can be changed with `notify.timeout`. + +Furthermore, the you can customize the notification messages with `notify.message`. For the `new` and `delete` messages, you can use `` and ``, which will be replaced by the respective new/deleted bookmark's associated key and folder. From a7e4a2156504423d3daca74492601e16992024cc Mon Sep 17 00:00:00 2001 From: Diogo Duarte Date: Sun, 31 Mar 2024 18:44:27 +0100 Subject: [PATCH 07/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f143bea..e8dc335 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ require("bookmarks"):setup({ When enabled, a new bookmark is automatically created in `''` which allows the user to jump back to the last directory. -### Notify +### `notify` When enabled, notifications will be shown when the user creates a new bookmark and deletes one or all saved bookmarks. From 07d6a35ffc166d31f056485b1e5efdbdf800964d Mon Sep 17 00:00:00 2001 From: Diogo Duarte Date: Sun, 31 Mar 2024 18:45:43 +0100 Subject: [PATCH 08/10] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e8dc335..1f76544 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ the last directory. When enabled, notifications will be shown when the user creates a new bookmark and deletes one or all saved bookmarks. -By default the notification as a 1 second timeout that can be changed with `notify.timeout`. +By default the notification has a 1 second timeout that can be changed with `notify.timeout`. -Furthermore, the you can customize the notification messages with `notify.message`. -For the `new` and `delete` messages, you can use `` and ``, which will be replaced by the respective new/deleted bookmark's associated key and folder. +Furthermore, you can customize the notification messages with `notify.message`. +For the `new` and `delete` messages, the use `` and `` keywords can be use, which will be replaced by the respective new/deleted bookmark's associated key and folder. From 5b7722895c717c5ebf8ce16438c23fad1f9e756f Mon Sep 17 00:00:00 2001 From: Diogo Duarte Date: Sun, 31 Mar 2024 18:46:15 +0100 Subject: [PATCH 09/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1f76544..a196a1e 100644 --- a/README.md +++ b/README.md @@ -77,4 +77,4 @@ all saved bookmarks. By default the notification has a 1 second timeout that can be changed with `notify.timeout`. Furthermore, you can customize the notification messages with `notify.message`. -For the `new` and `delete` messages, the use `` and `` keywords can be use, which will be replaced by the respective new/deleted bookmark's associated key and folder. +For the `new` and `delete` messages, the `` and `` keywords can be used, which will be replaced by the respective new/deleted bookmark's associated key and folder. From 42378dbb1b3ad2601abbd38d7cab86ac1e432c4f Mon Sep 17 00:00:00 2001 From: Diogo Duarte Date: Mon, 1 Apr 2024 20:19:01 +0100 Subject: [PATCH 10/10] Removed FIX comments --- init.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/init.lua b/init.lua index 9c51070..44cc73b 100644 --- a/init.lua +++ b/init.lua @@ -89,7 +89,7 @@ end) local _save_last_directory = ya.sync(function(state) state.curr_dir = { on = "'", - desc = "~", -- FIX This might not be true, i.e. the user entry point might not be the home dir + desc = "~", cursor = 0, } @@ -106,7 +106,6 @@ local _save_last_directory = ya.sync(function(state) ps.sub("hover", function() local folder = Folder:by_kind(Folder.CURRENT) state.curr_dir.cursor = folder.cursor - state.curr_dir.desc = tostring(folder.cwd) -- FIX Not needed when the we are able to get the CWD in the setup end) end)