From be45ad73674e3cf046d41b083fc62d1f8e44a5bb Mon Sep 17 00:00:00 2001 From: Diogo Duarte Date: Fri, 9 Feb 2024 19:17:17 +0000 Subject: [PATCH] Add 'delete' and 'deleteall' commands --- README.md | 16 +++++++++++++++- init.lua | 25 ++++++++++++++++++++----- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 38d207b..c02a959 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Bookmarks.yazi -Simple implementation of [vi-like marks](https://neovim.io/doc/user/motion.html#mark-motions) for [yazi](https://github.com/sxyazi/yazi). +A [Yazi](https://github.com/sxyazi/yazi) plugin that adds the basic functionality of [vi-like marks](https://neovim.io/doc/user/motion.html#mark-motions). ```toml [[manager.prepend_keymap]] @@ -15,3 +15,17 @@ on = [ "'" ] exec = "plugin bookmarks --sync --args='jump'" desc = "Jump to a bookmark" ``` + +```toml +[[manager.prepend_keymap]] +on = [ "b", "d" ] +exec = "plugin bookmarks --sync --args='delete'" +desc = "Jump to a bookmark" +``` + +```toml +[[manager.prepend_keymap]] +on = [ "b", "D" ] +exec = "plugin bookmarks --sync --args='deleteall'" +desc = "Jump to a bookmark" +``` diff --git a/init.lua b/init.lua index 26178b0..f070d62 100644 --- a/init.lua +++ b/init.lua @@ -37,6 +37,15 @@ local function jump_to_bookmark(bookmark) ya.manager_emit("arrow", { selected_bookmark.cursor }) end +local function delete_bookmark(bookmark) + state.bookmarks = state.bookmarks or {} + state.bookmarks[bookmark] = nil +end + +local function delete_all_bookmarks() + state.bookmarks = nil +end + local function next(sync, args) ya.manager_emit("plugin", { "bookmarks", sync = sync, args = table.concat(args, " ") }) end @@ -67,12 +76,12 @@ return { end next(true, { "set", key }) - elseif action == "jump" then + elseif action == "jump" or action == "delete" then local bookmark = args[2] if not bookmark then -- tried to use ya.sync but was unsuccessful, doing this way for the moment if state.bookmarks then - local arguments = { "_jump" } + local arguments = { "_" .. action } for k, _ in pairs(state.bookmarks) do table.insert(arguments, k) table.insert(arguments, state.bookmarks[k].path) @@ -80,9 +89,13 @@ return { next(false, arguments) end else - jump_to_bookmark(bookmark) + if action == "jump" then + jump_to_bookmark(bookmark) + elseif action == "delete" then + delete_bookmark(bookmark) + end end - elseif action == "_jump" then + elseif action == "_jump" or action == "_delete" then if #args == 1 then -- Should never enter here, but just to be safe return @@ -102,7 +115,9 @@ return { return end - next(true, { "jump", marked_keys[selected_bookmark].on }) + next(true, { string.sub(action, 2), marked_keys[selected_bookmark].on }) + elseif action == "deleteall" then + delete_all_bookmarks() end end, }