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:
35
README.md
35
README.md
@@ -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).
|
||||
|
||||
> [!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
|
||||
- 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
|
||||
|
||||
@@ -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,
|
||||
@@ -84,12 +86,23 @@ 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`
|
||||
|
||||
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
|
||||
|
||||
45
init.lua
45
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,26 +90,28 @@ 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)
|
||||
|
||||
-- ***********************************************
|
||||
-- **============= C O M M A N D S =============**
|
||||
-- ***********************************************/
|
||||
-- ***********************************************
|
||||
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user