From 06a226ba4afeef78cd80ea6fb9d93aa9128c5325 Mon Sep 17 00:00:00 2001 From: Diogo Duarte Date: Tue, 14 May 2024 10:39:43 +0100 Subject: [PATCH 1/3] add support for showing just the path of the folder in the desc, instead of the full path --- init.lua | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/init.lua b/init.lua index aa3196f..dd77d40 100644 --- a/init.lua +++ b/init.lua @@ -35,11 +35,23 @@ end) local _get_hovered_file = ya.sync(function() local folder = Folder:by_kind(Folder.CURRENT) - local file_hovered = folder.window[folder.cursor - folder.offset + 1] - if not file_hovered then - return folder.cwd + if not folder.hovered then + return { url = folder.cwd, is_cwd = true } end - return file_hovered.url + return { url = folder.hovered.url, is_cwd = false } +end) + +local _generate_description = ya.sync(function(state, file) + -- if this is true, we don't have information about the folder, so just return the folder url + if file.is_cwd then + return tostring(file.url) + end + + if state.desc_format == "parent" then + return tostring(file.url:parent()) + end + -- full description + return tostring(file.url) end) local _load_state = ya.sync(function(state) @@ -78,17 +90,19 @@ end) local _save_last_directory = ya.sync(function(state) ps.sub("cd", function() - local file_url = _get_hovered_file() + local file = _get_hovered_file() state.last_dir = state.curr_dir state.curr_dir = { on = "'", - desc = tostring(file_url), + desc = _generate_description(file), + path = tostring(file.url), } end) ps.sub("hover", function() - local file_url = _get_hovered_file() - state.curr_dir.desc = tostring(file_url) + local file = _get_hovered_file() + state.curr_dir.desc = _generate_description(file) + state.curr_dir.path = tostring(file.url) end) end) @@ -97,7 +111,7 @@ end) -- ***********************************************/ local save_bookmark = ya.sync(function(state, idx) - local file_url = _get_hovered_file() + local file = _get_hovered_file() state.bookmarks = state.bookmarks or {} @@ -108,7 +122,8 @@ local save_bookmark = ya.sync(function(state, idx) state.bookmarks[_idx] = { on = SUPPORTED_KEYS[idx].on, - desc = tostring(file_url), + desc = _generate_description(file), + path = tostring(file.url), } if state.persist then @@ -192,7 +207,7 @@ return { end if action == "jump" then - ya.manager_emit("reveal", { bookmarks[selected].desc }) + ya.manager_emit("reveal", { bookmarks[selected].path }) elseif action == "delete" then delete_bookmark(selected) end @@ -211,6 +226,12 @@ return { _load_state() end + if args.desc_format == "parent" then + state.desc_format = "parent" + else + state.desc_format = "full" + end + state.notify = { enable = false, timeout = 1, From b17e14e9e00608af32c6a2233908fb3de3aeb939 Mon Sep 17 00:00:00 2001 From: Diogo Duarte Date: Tue, 14 May 2024 10:48:01 +0100 Subject: [PATCH 2/3] Update README.md --- README.md | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e8cb3e3..5b86ac8 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,12 @@ 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). -> [!NOTE] -> Version 0.2.5+ or the latest main branch of Yazi is required. - https://github.com/dedukun/bookmarks.yazi/assets/25795432/9a9fe345-dd06-442e-99f1-8475ab22fad5 +## Requirements + +- [Yazi](https://github.com/sxyazi/yazi) v0.2.5+ + ## Features - Create/delete bookmarks @@ -60,6 +61,7 @@ The following are the default configurations: require("bookmarks"):setup({ save_last_directory = false, persist = "none", + desc_format = "full", notify = { enable = false, timeout = 1, @@ -90,6 +92,17 @@ There are three possible values for this option: | `all` | All the bookmarks are saved in persistent memory | | `vim` | This mode emulates the vim global marks, i.e., only the bookmarks in upper case (A-Z) are saved to persistent memory | +### `desc_format` + +The format for the bookmark description. + +There are two possible values for this option: + +| Value | Description | +| -------- | -------------------------------------------------------------------------------------------------------------------- | +| `full` | The default, it shows the full path of the bookmark, i.e., the parent folder + the hovered file | +| `parent` | Only shows the parent folder of the bookmark | + ### `notify` When enabled, notifications will be shown when the user creates a new bookmark and deletes one or From 300d6c2fd92d3c8a0acf1e632b35d1eac134196e Mon Sep 17 00:00:00 2001 From: Diogo Duarte Date: Tue, 14 May 2024 11:01:43 +0100 Subject: [PATCH 3/3] format --- README.md | 24 ++++++++++++------------ init.lua | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 5b86ac8..3ead7ce 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,10 @@ https://github.com/dedukun/bookmarks.yazi/assets/25795432/9a9fe345-dd06-442e-99f ## Features - - Create/delete bookmarks - - Custom Notifications - - `''` to go back to the previous folder - - Bookmarks persistence +- Create/delete bookmarks +- Custom Notifications +- `''` to go back to the previous folder +- Bookmarks persistence ## Installation @@ -86,10 +86,10 @@ present. There are three possible values for this option: -| Value | Description | -| ------ | ---------------------------------------------------------------------------------------------------------------------- | -| `none` | The default value, i.e., no persistance | -| `all` | All the bookmarks are saved in persistent memory | +| Value | Description | +| ------ | -------------------------------------------------------------------------------------------------------------------- | +| `none` | The default value, i.e., no persistance | +| `all` | All the bookmarks are saved in persistent memory | | `vim` | This mode emulates the vim global marks, i.e., only the bookmarks in upper case (A-Z) are saved to persistent memory | ### `desc_format` @@ -98,10 +98,10 @@ The format for the bookmark description. There are two possible values for this option: -| Value | Description | -| -------- | -------------------------------------------------------------------------------------------------------------------- | -| `full` | The default, it shows the full path of the bookmark, i.e., the parent folder + the hovered file | -| `parent` | Only shows the parent folder of the bookmark | +| Value | Description | +| -------- | ----------------------------------------------------------------------------------------------- | +| `full` | The default, it shows the full path of the bookmark, i.e., the parent folder + the hovered file | +| `parent` | Only shows the parent folder of the bookmark | ### `notify` diff --git a/init.lua b/init.lua index dd77d40..68fe4b6 100644 --- a/init.lua +++ b/init.lua @@ -108,7 +108,7 @@ end) -- *********************************************** -- **============= C O M M A N D S =============** --- ***********************************************/ +-- *********************************************** local save_bookmark = ya.sync(function(state, idx) local file = _get_hovered_file()