Compare commits
30 Commits
0.2.5
...
custom_key
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e45dffc27a | ||
|
|
0e772b951b | ||
|
|
fe0b1de939 | ||
|
|
420a384f51 | ||
|
|
af92d051ee | ||
|
|
3382460eb0 | ||
|
|
14573ea884 | ||
|
|
202e450b00 | ||
|
|
5116df5e95 | ||
|
|
35da1073b7 | ||
|
|
a91fe1cb85 | ||
|
|
20ece7e1ef | ||
|
|
e755ebc1e6 | ||
|
|
d9b722a7e4 | ||
|
|
600f87c021 | ||
|
|
ae06e0c1c0 | ||
|
|
6769310fa2 | ||
|
|
5b4258225b | ||
|
|
7ef1a95da1 | ||
|
|
53ae96aed8 | ||
|
|
17702a3752 | ||
|
|
f65fa5e7e9 | ||
|
|
5039aaa7d3 | ||
|
|
944f7fd2b3 | ||
|
|
a5a4ea1bd1 | ||
|
|
feffe662ee | ||
|
|
748efed3b9 | ||
|
|
b5dd86a7dd | ||
|
|
08b3f85c5d | ||
|
|
15304f3535 |
61
README.md
61
README.md
@@ -6,7 +6,7 @@ https://github.com/dedukun/bookmarks.yazi/assets/25795432/9a9fe345-dd06-442e-99f
|
||||
|
||||
## Requirements
|
||||
|
||||
- [Yazi](https://github.com/sxyazi/yazi) v0.2.5+
|
||||
- [Yazi](https://github.com/sxyazi/yazi) v25.2.7+
|
||||
|
||||
## Features
|
||||
|
||||
@@ -17,35 +17,16 @@ https://github.com/dedukun/bookmarks.yazi/assets/25795432/9a9fe345-dd06-442e-99f
|
||||
|
||||
## Installation
|
||||
|
||||
<details>
|
||||
<summary>Yazi v0.2.5 (manual installation)</summary>
|
||||
|
||||
```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
|
||||
|
||||
# Install plugin
|
||||
ya pack -i
|
||||
|
||||
# Update plugin
|
||||
ya pack -u
|
||||
```
|
||||
|
||||
</details>
|
||||
## Import/Export bookmarks
|
||||
|
||||
This plugin uses [Yazi's DDS](https://yazi-rs.github.io/docs/dds/) for bookmark persistence, as such,
|
||||
the bookmarks are saved in DDS's state file (`~/.local/state/yazi/.dds` on Linux and `C:\Users\USERNAME\AppData\Roaming\yazi\state\.dds` on Windows)
|
||||
|
||||
**_NOTE:_** This system may be used by other plugins that you have installed, so this file might have more data than just the bookmarks.
|
||||
|
||||
## Configuration
|
||||
|
||||
@@ -54,22 +35,22 @@ Add this to your `keymap.toml`:
|
||||
```toml
|
||||
[[manager.prepend_keymap]]
|
||||
on = [ "m" ]
|
||||
run = "plugin bookmarks --args=save"
|
||||
run = "plugin bookmarks save"
|
||||
desc = "Save current position as a bookmark"
|
||||
|
||||
[[manager.prepend_keymap]]
|
||||
on = [ "'" ]
|
||||
run = "plugin bookmarks --args=jump"
|
||||
run = "plugin bookmarks jump"
|
||||
desc = "Jump to a bookmark"
|
||||
|
||||
[[manager.prepend_keymap]]
|
||||
on = [ "b", "d" ]
|
||||
run = "plugin bookmarks --args=delete"
|
||||
run = "plugin bookmarks delete"
|
||||
desc = "Delete a bookmark"
|
||||
|
||||
[[manager.prepend_keymap]]
|
||||
on = [ "b", "D" ]
|
||||
run = "plugin bookmarks --args=delete_all"
|
||||
run = "plugin bookmarks delete_all"
|
||||
desc = "Delete all bookmarks"
|
||||
```
|
||||
|
||||
@@ -81,9 +62,10 @@ The following are the default configurations:
|
||||
```lua
|
||||
-- ~/.config/yazi/init.lua
|
||||
require("bookmarks"):setup({
|
||||
save_last_directory = false,
|
||||
last_directory = { enable = false, persist = false, key= "'" },
|
||||
persist = "none",
|
||||
desc_format = "full",
|
||||
file_pick_mode = "hover",
|
||||
notify = {
|
||||
enable = false,
|
||||
timeout = 1,
|
||||
@@ -96,11 +78,15 @@ require("bookmarks"):setup({
|
||||
})
|
||||
```
|
||||
|
||||
### `save_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.
|
||||
|
||||
It's also possible to change the trigger key.
|
||||
|
||||
### `persist`
|
||||
|
||||
When enabled the bookmarks will persist, i.e. if you close and reopen Yazi they will still be
|
||||
@@ -125,6 +111,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 |
|
||||
| `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`
|
||||
|
||||
When enabled, notifications will be shown when the user creates a new bookmark and deletes one or
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
--- @since 25.2.7
|
||||
-- stylua: ignore
|
||||
local SUPPORTED_KEYS = {
|
||||
{ on = "0"}, { on = "1"}, { on = "2"}, { on = "3"}, { on = "4"},
|
||||
@@ -33,17 +34,18 @@ local _get_real_index = ya.sync(function(state, idx)
|
||||
return nil
|
||||
end)
|
||||
|
||||
local _get_hovered_file = ya.sync(function()
|
||||
local folder = Folder:by_kind(Folder.CURRENT)
|
||||
if not folder.hovered then
|
||||
return { url = folder.cwd, is_cwd = true }
|
||||
local _get_bookmark_file = ya.sync(function(state)
|
||||
local folder = cx.active.current
|
||||
|
||||
if state.file_pick_mode == "parent" or not folder.hovered then
|
||||
return { url = folder.cwd, is_parent = true }
|
||||
end
|
||||
return { url = folder.hovered.url, is_cwd = false }
|
||||
return { url = folder.hovered.url, is_parent = 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
|
||||
if file.is_parent then
|
||||
return tostring(file.url)
|
||||
end
|
||||
|
||||
@@ -55,7 +57,7 @@ local _generate_description = ya.sync(function(state, file)
|
||||
end)
|
||||
|
||||
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
|
||||
state.bookmarks = {}
|
||||
for _, value in pairs(body) do
|
||||
@@ -67,7 +69,7 @@ end)
|
||||
|
||||
local _save_state = ya.sync(function(state, bookmarks)
|
||||
if not bookmarks then
|
||||
ps.pub_static(10, "bookmarks", nil)
|
||||
ps.pub_to(0, "@bookmarks", nil)
|
||||
return
|
||||
end
|
||||
|
||||
@@ -85,22 +87,35 @@ local _save_state = ya.sync(function(state, bookmarks)
|
||||
end
|
||||
end
|
||||
|
||||
ps.pub_static(10, "bookmarks", save_state)
|
||||
ps.pub_to(0, "@bookmarks", save_state)
|
||||
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
|
||||
state.curr_dir.on = state.last_directory_key
|
||||
end)
|
||||
end
|
||||
|
||||
ps.sub("cd", function()
|
||||
local file = _get_hovered_file()
|
||||
local file = _get_bookmark_file()
|
||||
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 = {
|
||||
on = "'",
|
||||
on = state.last_directory_key,
|
||||
desc = _generate_description(file),
|
||||
path = tostring(file.url),
|
||||
is_parent = file.is_parent,
|
||||
}
|
||||
end)
|
||||
|
||||
ps.sub("hover", function()
|
||||
local file = _get_hovered_file()
|
||||
local file = _get_bookmark_file()
|
||||
state.curr_dir.desc = _generate_description(file)
|
||||
state.curr_dir.path = tostring(file.url)
|
||||
end)
|
||||
@@ -111,7 +126,7 @@ end)
|
||||
-- ***********************************************
|
||||
|
||||
local save_bookmark = ya.sync(function(state, idx)
|
||||
local file = _get_hovered_file()
|
||||
local file = _get_bookmark_file()
|
||||
|
||||
state.bookmarks = state.bookmarks or {}
|
||||
|
||||
@@ -124,8 +139,31 @@ local save_bookmark = ya.sync(function(state, idx)
|
||||
on = SUPPORTED_KEYS[idx].on,
|
||||
desc = _generate_description(file),
|
||||
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
|
||||
_save_state(state.bookmarks)
|
||||
end
|
||||
@@ -181,9 +219,17 @@ local delete_all_bookmarks = ya.sync(function(state)
|
||||
end
|
||||
end)
|
||||
|
||||
local jump_to_last = ya.sync(function(state)
|
||||
if state.last_dir.is_parent then
|
||||
ya.manager_emit("cd", { state.last_dir.is_parent })
|
||||
else
|
||||
ya.manager_emit("reveal", { state.last_dir.is_parent })
|
||||
end
|
||||
end)
|
||||
|
||||
return {
|
||||
entry = function(_, args)
|
||||
local action = args[1]
|
||||
entry = function(_, job)
|
||||
local action = job.args[1]
|
||||
if not action then
|
||||
return
|
||||
end
|
||||
@@ -194,10 +240,10 @@ return {
|
||||
save_bookmark(key)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if action == "delete_all" then
|
||||
elseif action == "delete_all" then
|
||||
return delete_all_bookmarks()
|
||||
elseif action == "jump_last" then
|
||||
return jump_to_last()
|
||||
end
|
||||
|
||||
local bookmarks = all_bookmarks(action == "jump")
|
||||
@@ -207,7 +253,11 @@ return {
|
||||
end
|
||||
|
||||
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
|
||||
delete_bookmark(selected)
|
||||
end
|
||||
@@ -217,8 +267,15 @@ return {
|
||||
return
|
||||
end
|
||||
|
||||
if args.save_last_directory then
|
||||
_save_last_directory()
|
||||
if type(args.last_directory) == "table" then
|
||||
if args.last_directory.enable then
|
||||
state.last_directory_key = "'"
|
||||
if type(args.last_directory.key) == "string" then
|
||||
state.last_directory_key = args.last_directory.key
|
||||
end
|
||||
|
||||
_save_last_directory(args.last_directory.persist)
|
||||
end
|
||||
end
|
||||
|
||||
if args.persist == "all" or args.persist == "vim" then
|
||||
@@ -232,6 +289,12 @@ return {
|
||||
state.desc_format = "full"
|
||||
end
|
||||
|
||||
if args.file_pick_mode == "parent" then
|
||||
state.file_pick_mode = "parent"
|
||||
else
|
||||
state.file_pick_mode = "hover"
|
||||
end
|
||||
|
||||
state.notify = {
|
||||
enable = false,
|
||||
timeout = 1,
|
||||
Reference in New Issue
Block a user