9 Commits

Author SHA1 Message Date
Diogo Duarte
e45dffc27a Update README 2025-02-18 23:13:40 +00:00
Diogo Duarte
0e772b951b Add custom keybinding for last + added 'jump' command 2025-02-18 23:03:00 +00:00
Diogo Duarte
fe0b1de939 minimum required version is now Yazi v25.2.7 2025-02-18 11:15:14 +00:00
Diogo Duarte
420a384f51 Merge pull request #37 from dedukun/import-export-readme
Update README with import/export documentation
2025-02-16 18:42:41 +00:00
Diogo Duarte
af92d051ee Merge branch 'main' into import-export-readme 2025-02-16 18:42:05 +00:00
Diogo Duarte
3382460eb0 Update README.md 2025-02-16 18:38:11 +00:00
Diogo Duarte
14573ea884 Update README.md 2025-01-29 18:08:36 +00:00
Diogo Duarte
202e450b00 Update README.md 2025-01-07 14:58:11 +00:00
Diogo Duarte
5116df5e95 Remove deprecated code 2025-01-06 11:48:18 +00:00
2 changed files with 44 additions and 32 deletions

View File

@@ -6,7 +6,7 @@ https://github.com/dedukun/bookmarks.yazi/assets/25795432/9a9fe345-dd06-442e-99f
## Requirements
- [Yazi](https://github.com/sxyazi/yazi) v0.3.0+
- [Yazi](https://github.com/sxyazi/yazi) v25.2.7+
## Features
@@ -21,6 +21,13 @@ https://github.com/dedukun/bookmarks.yazi/assets/25795432/9a9fe345-dd06-442e-99f
ya pack -a dedukun/bookmarks
```
## 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
Add this to your `keymap.toml`:
@@ -28,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"
```
@@ -55,8 +62,7 @@ The following are the default configurations:
```lua
-- ~/.config/yazi/init.lua
require("bookmarks"):setup({
save_last_directory = false, -- DEPRECATED - will be removed in the future. Use `last_directory`
last_directory = { enable = false, persist = false },
last_directory = { enable = false, persist = false, key= "'" },
persist = "none",
desc_format = "full",
file_pick_mode = "hover",
@@ -72,13 +78,6 @@ require("bookmarks"):setup({
})
```
### `save_last_directory`
When enabled, a new bookmark is automatically created in `'` which allows the user to jump back to
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
@@ -86,6 +85,8 @@ 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
@@ -116,10 +117,10 @@ 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 |
| 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`

View File

@@ -1,3 +1,4 @@
--- @since 25.2.7
-- stylua: ignore
local SUPPORTED_KEYS = {
{ on = "0"}, { on = "1"}, { on = "2"}, { on = "3"}, { on = "4"},
@@ -91,7 +92,10 @@ end)
local _save_last_directory = ya.sync(function(state, persist)
if persist then
ps.sub_remote("@bookmarks-lastdir", function(body) state.curr_dir = body end)
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()
@@ -103,7 +107,7 @@ local _save_last_directory = ya.sync(function(state, persist)
end
state.curr_dir = {
on = "'",
on = state.last_directory_key,
desc = _generate_description(file),
path = tostring(file.url),
is_parent = file.is_parent,
@@ -215,12 +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(_, 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]
entry = function(_, job)
local action = job.args[1]
if not action then
return
end
@@ -231,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")
@@ -258,11 +267,13 @@ return {
return
end
-- TODO: DEPRECATED Yazi 0.4
if args.save_last_directory then
_save_last_directory()
elseif type(args.last_directory) == "table" then
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