Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35da1073b7 | ||
|
|
a91fe1cb85 | ||
|
|
20ece7e1ef | ||
|
|
e755ebc1e6 | ||
|
|
d9b722a7e4 | ||
|
|
600f87c021 | ||
|
|
ae06e0c1c0 | ||
|
|
6769310fa2 | ||
|
|
5b4258225b | ||
|
|
7ef1a95da1 | ||
|
|
53ae96aed8 | ||
|
|
17702a3752 | ||
|
|
f65fa5e7e9 | ||
|
|
5039aaa7d3 | ||
|
|
944f7fd2b3 | ||
|
|
a5a4ea1bd1 | ||
|
|
feffe662ee | ||
|
|
748efed3b9 | ||
|
|
b5dd86a7dd | ||
|
|
08b3f85c5d | ||
|
|
15304f3535 |
52
README.md
52
README.md
@@ -6,7 +6,7 @@ https://github.com/dedukun/bookmarks.yazi/assets/25795432/9a9fe345-dd06-442e-99f
|
|||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
- [Yazi](https://github.com/sxyazi/yazi) v0.2.5+
|
- [Yazi](https://github.com/sxyazi/yazi) v0.3.0+
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
@@ -17,36 +17,10 @@ https://github.com/dedukun/bookmarks.yazi/assets/25795432/9a9fe345-dd06-442e-99f
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>Yazi v0.2.5 (manual installation)</summary>
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# Linux/macOS
|
|
||||||
git clone https://github.com/dedukun/bookmarks.yazi.git ~/.config/yazi/plugins/bookmarks.yazi
|
|
||||||
|
|
||||||
# Windows
|
|
||||||
git clone https://github.com/dedukun/bookmarks.yazi.git %AppData%\yazi\config\plugins\bookmarks.yazi
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>Latest commit in Yazi (package manager)</summary>
|
|
||||||
|
|
||||||
```sh
|
|
||||||
# Add the plugin
|
|
||||||
ya pack -a dedukun/bookmarks
|
ya pack -a dedukun/bookmarks
|
||||||
|
|
||||||
# Install plugin
|
|
||||||
ya pack -i
|
|
||||||
|
|
||||||
# Update plugin
|
|
||||||
ya pack -u
|
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
Add this to your `keymap.toml`:
|
Add this to your `keymap.toml`:
|
||||||
@@ -81,9 +55,11 @@ The following are the default configurations:
|
|||||||
```lua
|
```lua
|
||||||
-- ~/.config/yazi/init.lua
|
-- ~/.config/yazi/init.lua
|
||||||
require("bookmarks"):setup({
|
require("bookmarks"):setup({
|
||||||
save_last_directory = false,
|
save_last_directory = false, -- DEPRECATED - will be removed in the future. Use `last_directory`
|
||||||
|
last_directory = { enable = false, persist = false },
|
||||||
persist = "none",
|
persist = "none",
|
||||||
desc_format = "full",
|
desc_format = "full",
|
||||||
|
file_pick_mode = "hover",
|
||||||
notify = {
|
notify = {
|
||||||
enable = false,
|
enable = false,
|
||||||
timeout = 1,
|
timeout = 1,
|
||||||
@@ -101,6 +77,15 @@ require("bookmarks"):setup({
|
|||||||
When enabled, a new bookmark is automatically created in `'` which allows the user to jump back to
|
When enabled, a new bookmark is automatically created in `'` which allows the user to jump back to
|
||||||
the last directory.
|
the last directory.
|
||||||
|
|
||||||
|
***NOTE:*** This option is **DEPRECATED** and will be removed in the future in favor of `last_directory`.
|
||||||
|
|
||||||
|
### `last_directory`
|
||||||
|
|
||||||
|
When enabled, a new bookmark is automatically created in `'` which allows the user to jump back to
|
||||||
|
the last directory.
|
||||||
|
|
||||||
|
There's also the option to enable persistence to this automatic bookmark.
|
||||||
|
|
||||||
### `persist`
|
### `persist`
|
||||||
|
|
||||||
When enabled the bookmarks will persist, i.e. if you close and reopen Yazi they will still be
|
When enabled the bookmarks will persist, i.e. if you close and reopen Yazi they will still be
|
||||||
@@ -125,6 +110,17 @@ There are two possible values for this option:
|
|||||||
| `full` | The default, it shows the full path of the bookmark, i.e., the parent folder + the hovered file |
|
| `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 |
|
| `parent` | Only shows the parent folder of the bookmark |
|
||||||
|
|
||||||
|
### `file_pick_mode`
|
||||||
|
|
||||||
|
The mode for choosing which directory to bookmark.
|
||||||
|
|
||||||
|
There are two possible values for this option:
|
||||||
|
|
||||||
|
| Value | Description |
|
||||||
|
| -------- | ----------------------------------------------------------------------------------------------- |
|
||||||
|
| `hover` | The default, it uses the path of the hovered file for new bookmarks |
|
||||||
|
| `parent` | Uses the path of the parent folder for new bookmarks |
|
||||||
|
|
||||||
### `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
|
||||||
|
|||||||
82
init.lua
82
init.lua
@@ -33,17 +33,18 @@ local _get_real_index = ya.sync(function(state, idx)
|
|||||||
return nil
|
return nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local _get_hovered_file = ya.sync(function()
|
local _get_bookmark_file = ya.sync(function(state)
|
||||||
local folder = Folder:by_kind(Folder.CURRENT)
|
local folder = cx.active.current
|
||||||
if not folder.hovered then
|
|
||||||
return { url = folder.cwd, is_cwd = true }
|
if state.file_pick_mode == "parent" or not folder.hovered then
|
||||||
|
return { url = folder.cwd, is_parent = true }
|
||||||
end
|
end
|
||||||
return { url = folder.hovered.url, is_cwd = false }
|
return { url = folder.hovered.url, is_parent = false }
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local _generate_description = ya.sync(function(state, file)
|
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 this is true, we don't have information about the folder, so just return the folder url
|
||||||
if file.is_cwd then
|
if file.is_parent then
|
||||||
return tostring(file.url)
|
return tostring(file.url)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -55,7 +56,7 @@ local _generate_description = ya.sync(function(state, file)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
local _load_state = ya.sync(function(state)
|
local _load_state = ya.sync(function(state)
|
||||||
ps.sub_remote("bookmarks", function(body)
|
ps.sub_remote("@bookmarks", function(body)
|
||||||
if not state.bookmarks and body then
|
if not state.bookmarks and body then
|
||||||
state.bookmarks = {}
|
state.bookmarks = {}
|
||||||
for _, value in pairs(body) do
|
for _, value in pairs(body) do
|
||||||
@@ -67,7 +68,7 @@ end)
|
|||||||
|
|
||||||
local _save_state = ya.sync(function(state, bookmarks)
|
local _save_state = ya.sync(function(state, bookmarks)
|
||||||
if not bookmarks then
|
if not bookmarks then
|
||||||
ps.pub_static(10, "bookmarks", nil)
|
ps.pub_to(0, "@bookmarks", nil)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -85,22 +86,32 @@ local _save_state = ya.sync(function(state, bookmarks)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ps.pub_static(10, "bookmarks", save_state)
|
ps.pub_to(0, "@bookmarks", save_state)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local _save_last_directory = ya.sync(function(state)
|
local _save_last_directory = ya.sync(function(state, persist)
|
||||||
|
if persist then
|
||||||
|
ps.sub_remote("@bookmarks-lastdir", function(body) state.curr_dir = body end)
|
||||||
|
end
|
||||||
|
|
||||||
ps.sub("cd", function()
|
ps.sub("cd", function()
|
||||||
local file = _get_hovered_file()
|
local file = _get_bookmark_file()
|
||||||
state.last_dir = state.curr_dir
|
state.last_dir = state.curr_dir
|
||||||
|
|
||||||
|
if persist and state.last_dir then
|
||||||
|
ps.pub_to(0, "@bookmarks-lastdir", state.last_dir)
|
||||||
|
end
|
||||||
|
|
||||||
state.curr_dir = {
|
state.curr_dir = {
|
||||||
on = "'",
|
on = "'",
|
||||||
desc = _generate_description(file),
|
desc = _generate_description(file),
|
||||||
path = tostring(file.url),
|
path = tostring(file.url),
|
||||||
|
is_parent = file.is_parent,
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
ps.sub("hover", function()
|
ps.sub("hover", function()
|
||||||
local file = _get_hovered_file()
|
local file = _get_bookmark_file()
|
||||||
state.curr_dir.desc = _generate_description(file)
|
state.curr_dir.desc = _generate_description(file)
|
||||||
state.curr_dir.path = tostring(file.url)
|
state.curr_dir.path = tostring(file.url)
|
||||||
end)
|
end)
|
||||||
@@ -111,7 +122,7 @@ end)
|
|||||||
-- ***********************************************
|
-- ***********************************************
|
||||||
|
|
||||||
local save_bookmark = ya.sync(function(state, idx)
|
local save_bookmark = ya.sync(function(state, idx)
|
||||||
local file = _get_hovered_file()
|
local file = _get_bookmark_file()
|
||||||
|
|
||||||
state.bookmarks = state.bookmarks or {}
|
state.bookmarks = state.bookmarks or {}
|
||||||
|
|
||||||
@@ -124,8 +135,31 @@ local save_bookmark = ya.sync(function(state, idx)
|
|||||||
on = SUPPORTED_KEYS[idx].on,
|
on = SUPPORTED_KEYS[idx].on,
|
||||||
desc = _generate_description(file),
|
desc = _generate_description(file),
|
||||||
path = tostring(file.url),
|
path = tostring(file.url),
|
||||||
|
is_parent = file.is_parent,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- Custom sorting function
|
||||||
|
table.sort(state.bookmarks, function(a, b)
|
||||||
|
local key_a, key_b = a.on, b.on
|
||||||
|
|
||||||
|
-- Numbers first
|
||||||
|
if key_a:match("%d") and not key_b:match("%d") then
|
||||||
|
return true
|
||||||
|
elseif key_b:match("%d") and not key_a:match("%d") then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Uppercase before lowercase
|
||||||
|
if key_a:match("%u") and key_b:match("%l") then
|
||||||
|
return true
|
||||||
|
elseif key_b:match("%u") and key_a:match("%l") then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Regular alphabetical sorting
|
||||||
|
return key_a < key_b
|
||||||
|
end)
|
||||||
|
|
||||||
if state.persist then
|
if state.persist then
|
||||||
_save_state(state.bookmarks)
|
_save_state(state.bookmarks)
|
||||||
end
|
end
|
||||||
@@ -182,7 +216,10 @@ local delete_all_bookmarks = ya.sync(function(state)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
entry = function(_, args)
|
entry = function(_, job_or_args)
|
||||||
|
-- TODO: DEPRECATE IN Yazi 0.4
|
||||||
|
-- https://github.com/sxyazi/yazi/pull/1966
|
||||||
|
local args = job_or_args.args or job_or_args
|
||||||
local action = args[1]
|
local action = args[1]
|
||||||
if not action then
|
if not action then
|
||||||
return
|
return
|
||||||
@@ -207,7 +244,11 @@ return {
|
|||||||
end
|
end
|
||||||
|
|
||||||
if action == "jump" then
|
if action == "jump" then
|
||||||
ya.manager_emit("reveal", { bookmarks[selected].path })
|
if bookmarks[selected].is_parent then
|
||||||
|
ya.manager_emit("cd", { bookmarks[selected].path })
|
||||||
|
else
|
||||||
|
ya.manager_emit("reveal", { bookmarks[selected].path })
|
||||||
|
end
|
||||||
elseif action == "delete" then
|
elseif action == "delete" then
|
||||||
delete_bookmark(selected)
|
delete_bookmark(selected)
|
||||||
end
|
end
|
||||||
@@ -217,8 +258,13 @@ return {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- TODO: DEPRECATED Yazi 0.4
|
||||||
if args.save_last_directory then
|
if args.save_last_directory then
|
||||||
_save_last_directory()
|
_save_last_directory()
|
||||||
|
elseif type(args.last_directory) == "table" then
|
||||||
|
if args.last_directory.enable then
|
||||||
|
_save_last_directory(args.last_directory.persist)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if args.persist == "all" or args.persist == "vim" then
|
if args.persist == "all" or args.persist == "vim" then
|
||||||
@@ -232,6 +278,12 @@ return {
|
|||||||
state.desc_format = "full"
|
state.desc_format = "full"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if args.file_pick_mode == "parent" then
|
||||||
|
state.file_pick_mode = "parent"
|
||||||
|
else
|
||||||
|
state.file_pick_mode = "hover"
|
||||||
|
end
|
||||||
|
|
||||||
state.notify = {
|
state.notify = {
|
||||||
enable = false,
|
enable = false,
|
||||||
timeout = 1,
|
timeout = 1,
|
||||||
|
|||||||
Reference in New Issue
Block a user