From e1ca89ed7f9e7c575eb5d486e6a4d6ccd5413b5d Mon Sep 17 00:00:00 2001 From: Diogo Duarte Date: Tue, 12 Mar 2024 14:07:53 +0000 Subject: [PATCH 1/4] added notification support for new bookmarks --- init.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/init.lua b/init.lua index 1df33ac..5be7e67 100644 --- a/init.lua +++ b/init.lua @@ -23,6 +23,17 @@ local save_bookmark = ya.sync(function(state, idx) desc = tostring(folder.cwd), cursor = folder.cursor, } + + if state.notify.enable then + local description = state.notify.format + description, _ = description:gsub("", SUPPORTED_KEYS[idx].on) + description, _ = description:gsub("", tostring(folder.cwd)) + ya.notify { + title = "Bookmarks", + content = description, + timeout = state.notify.timeout, + } + end end) local all_bookmarks = ya.sync(function(state) return state.bookmarks or {} end) @@ -64,4 +75,22 @@ return { delete_bookmark(selected) end end, + setup = function(state, args) + if not args then + return + end + + state.notify = { enable = false, timeout = 2, format = "New bookmark in '' -> ''" } + if args.notify ~= nil then + if type(args.notify.enable) == "boolean" then + state.notify.enable = args.notify.enable + end + if type(args.notify.timeout) == "number" then + state.notify.timeout = args.notify.timeout + end + if type(args.notify.format) == "string" then + state.notify.format = args.notify.format + end + end + end, } From 5a908d31d5076af60100543a5231c0a26a7ce492 Mon Sep 17 00:00:00 2001 From: Diogo Duarte Date: Tue, 12 Mar 2024 14:49:57 +0000 Subject: [PATCH 2/4] added notification for delete and delete_all --- init.lua | 59 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/init.lua b/init.lua index 5be7e67..6104584 100644 --- a/init.lua +++ b/init.lua @@ -25,12 +25,12 @@ local save_bookmark = ya.sync(function(state, idx) } if state.notify.enable then - local description = state.notify.format - description, _ = description:gsub("", SUPPORTED_KEYS[idx].on) - description, _ = description:gsub("", tostring(folder.cwd)) + local message = state.notify.message.new + message, _ = message:gsub("", SUPPORTED_KEYS[idx].on) + message, _ = message:gsub("", tostring(folder.cwd)) ya.notify { title = "Bookmarks", - content = description, + content = message, timeout = state.notify.timeout, } end @@ -38,9 +38,32 @@ end) local all_bookmarks = ya.sync(function(state) return state.bookmarks or {} end) -local delete_bookmark = ya.sync(function(state, idx) table.remove(state.bookmarks, idx) end) +local delete_bookmark = ya.sync(function(state, idx) + if state.notify.enable then + local message = state.notify.message.delete + message, _ = message:gsub("", state.bookmarks[idx].on) + message, _ = message:gsub("", state.bookmarks[idx].desc) + ya.notify { + title = "Bookmarks", + content = message, + timeout = state.notify.timeout, + } + end -local delete_all_bookmarks = ya.sync(function(state) state.bookmarks = nil end) + table.remove(state.bookmarks, idx) +end) + +local delete_all_bookmarks = ya.sync(function(state) + state.bookmarks = nil + + if state.notify.enable then + ya.notify { + title = "Bookmarks", + content = state.notify.message.delete_all, + timeout = state.notify.timeout, + } + end +end) return { entry = function(_, args) @@ -80,16 +103,32 @@ return { return end - state.notify = { enable = false, timeout = 2, format = "New bookmark in '' -> ''" } - if args.notify ~= nil then + state.notify = { + enable = false, + timeout = 1, + message = { + new = "New bookmark '' -> ''", + delete = "Deleted bookmark in ''", + delete_all = "Deleted all bookmarks", + }, + } + if type(args.notify) == "table" then if type(args.notify.enable) == "boolean" then state.notify.enable = args.notify.enable end if type(args.notify.timeout) == "number" then state.notify.timeout = args.notify.timeout end - if type(args.notify.format) == "string" then - state.notify.format = args.notify.format + if type(args.notify.message) == "table" then + if type(args.notify.message.new) == "string" then + state.notify.message.new = args.notify.message.new + end + if type(args.notify.message.delete) == "string" then + state.notify.message.delete = args.notify.message.delete + end + if type(args.notify.message.delete_all) == "string" then + state.notify.message.delete_all = args.notify.message.delete_all + end end end end, From a72bddd492ae903854c604acd92bbb429d51a0cc Mon Sep 17 00:00:00 2001 From: Diogo Duarte Date: Tue, 12 Mar 2024 15:21:14 +0000 Subject: [PATCH 3/4] Update README.md --- README.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dae70a1..30dad0f 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ git clone https://github.com/dedukun/bookmarks.yazi.git ~/.config/yazi/plugins/b git clone https://github.com/dedukun/bookmarks.yazi.git %AppData%\yazi\config\plugins\bookmarks.yazi ``` -## Usage +## Configuration Add this to your `keymap.toml`: @@ -42,3 +42,23 @@ on = [ "b", "D" ] exec = "plugin bookmarks --args=delete_all" desc = "Delete all bookmarks" ``` + +--- + +Additionally you can enable notifications via the plugin's `setup` function in `init.lua`, the following are the default configurations: + +```lua +require("bookmarks"):setup({ + notify = { + enable = false, + timeout = 1, + message = { + new = "New bookmark '' -> ''", + delete = "Deleted bookmark in ''", + delete_all = "Deleted all bookmarks", + }, + }, +}) +``` + +For the `new` and `delete` messages, you can use `` and ``, which will be replaced by the repective new/deleted bookmark's associated key and folder. From 25d1c05b4f9f542230ee45aa6a008b8a0d9422e1 Mon Sep 17 00:00:00 2001 From: Diogo Duarte Date: Tue, 12 Mar 2024 15:25:33 +0000 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 30dad0f..c188c9c 100644 --- a/README.md +++ b/README.md @@ -61,4 +61,4 @@ require("bookmarks"):setup({ }) ``` -For the `new` and `delete` messages, you can use `` and ``, which will be replaced by the repective new/deleted bookmark's associated key and folder. +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.