Merge pull request #17 from dedukun/new_desc

Add support for showing just the name of the bookmarked folder in the description
This commit is contained in:
Diogo Duarte
2024-05-15 09:56:51 +01:00
committed by GitHub
2 changed files with 57 additions and 23 deletions

View File

@@ -2,17 +2,18 @@
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). 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 https://github.com/dedukun/bookmarks.yazi/assets/25795432/9a9fe345-dd06-442e-99f1-8475ab22fad5
## Requirements
- [Yazi](https://github.com/sxyazi/yazi) v0.2.5+
## Features ## Features
- Create/delete bookmarks - Create/delete bookmarks
- Custom Notifications - Custom Notifications
- `''` to go back to the previous folder - `''` to go back to the previous folder
- Bookmarks persistence - Bookmarks persistence
## Installation ## Installation
@@ -60,6 +61,7 @@ The following are the default configurations:
require("bookmarks"):setup({ require("bookmarks"):setup({
save_last_directory = false, save_last_directory = false,
persist = "none", persist = "none",
desc_format = "full",
notify = { notify = {
enable = false, enable = false,
timeout = 1, timeout = 1,
@@ -84,12 +86,23 @@ present.
There are three possible values for this option: There are three possible values for this option:
| Value | Description | | Value | Description |
| ------ | ---------------------------------------------------------------------------------------------------------------------- | | ------ | -------------------------------------------------------------------------------------------------------------------- |
| `none` | The default value, i.e., no persistance | | `none` | The default value, i.e., no persistance |
| `all` | All the bookmarks are saved in persistent memory | | `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 | | `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` ### `notify`
When enabled, notifications will be shown when the user creates a new bookmark and deletes one or When enabled, notifications will be shown when the user creates a new bookmark and deletes one or

View File

@@ -35,11 +35,23 @@ end)
local _get_hovered_file = ya.sync(function() local _get_hovered_file = ya.sync(function()
local folder = Folder:by_kind(Folder.CURRENT) local folder = Folder:by_kind(Folder.CURRENT)
local file_hovered = folder.window[folder.cursor - folder.offset + 1] if not folder.hovered then
if not file_hovered then return { url = folder.cwd, is_cwd = true }
return folder.cwd
end 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) end)
local _load_state = ya.sync(function(state) local _load_state = ya.sync(function(state)
@@ -78,26 +90,28 @@ end)
local _save_last_directory = ya.sync(function(state) local _save_last_directory = ya.sync(function(state)
ps.sub("cd", function() ps.sub("cd", function()
local file_url = _get_hovered_file() local file = _get_hovered_file()
state.last_dir = state.curr_dir state.last_dir = state.curr_dir
state.curr_dir = { state.curr_dir = {
on = "'", on = "'",
desc = tostring(file_url), desc = _generate_description(file),
path = tostring(file.url),
} }
end) end)
ps.sub("hover", function() ps.sub("hover", function()
local file_url = _get_hovered_file() local file = _get_hovered_file()
state.curr_dir.desc = tostring(file_url) state.curr_dir.desc = _generate_description(file)
state.curr_dir.path = tostring(file.url)
end) end)
end) end)
-- *********************************************** -- ***********************************************
-- **============= C O M M A N D S =============** -- **============= C O M M A N D S =============**
-- ***********************************************/ -- ***********************************************
local save_bookmark = ya.sync(function(state, idx) local save_bookmark = ya.sync(function(state, idx)
local file_url = _get_hovered_file() local file = _get_hovered_file()
state.bookmarks = state.bookmarks or {} state.bookmarks = state.bookmarks or {}
@@ -108,7 +122,8 @@ local save_bookmark = ya.sync(function(state, idx)
state.bookmarks[_idx] = { state.bookmarks[_idx] = {
on = SUPPORTED_KEYS[idx].on, on = SUPPORTED_KEYS[idx].on,
desc = tostring(file_url), desc = _generate_description(file),
path = tostring(file.url),
} }
if state.persist then if state.persist then
@@ -192,7 +207,7 @@ return {
end end
if action == "jump" then if action == "jump" then
ya.manager_emit("reveal", { bookmarks[selected].desc }) ya.manager_emit("reveal", { bookmarks[selected].path })
elseif action == "delete" then elseif action == "delete" then
delete_bookmark(selected) delete_bookmark(selected)
end end
@@ -211,6 +226,12 @@ return {
_load_state() _load_state()
end end
if args.desc_format == "parent" then
state.desc_format = "parent"
else
state.desc_format = "full"
end
state.notify = { state.notify = {
enable = false, enable = false,
timeout = 1, timeout = 1,