Compare commits
15 Commits
0.3.3
...
last_dir_m
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
430592ba57 | ||
|
|
7a2f62fbb3 | ||
|
|
d897f6b0bd | ||
|
|
a7963b784a | ||
|
|
e2614a18fc | ||
|
|
a0c8299704 | ||
|
|
2fc6a0a938 | ||
|
|
fe0b1de939 | ||
|
|
023bde5a53 | ||
|
|
420a384f51 | ||
|
|
af92d051ee | ||
|
|
3382460eb0 | ||
|
|
14573ea884 | ||
|
|
202e450b00 | ||
|
|
5116df5e95 |
44
README.md
44
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.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,11 +62,11 @@ 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, mode="dir" },
|
||||
persist = "none",
|
||||
desc_format = "full",
|
||||
file_pick_mode = "hover",
|
||||
custom_desc_input = false,
|
||||
notify = {
|
||||
enable = false,
|
||||
timeout = 1,
|
||||
@@ -72,13 +79,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 +86,14 @@ the last directory.
|
||||
|
||||
There's also the option to enable persistence to this automatic bookmark.
|
||||
|
||||
Finally, there's a `mode` option with the following options:
|
||||
|
||||
| Value | Description |
|
||||
| ------ | ------------------------------------------------------------ |
|
||||
| `jump` | It saves the position before the last used mark |
|
||||
| `mark` | It saves the last created mark |
|
||||
| `dir` | Default, it saves the last visited directory (old behaviour) |
|
||||
|
||||
### `persist`
|
||||
|
||||
When enabled the bookmarks will persist, i.e. if you close and reopen Yazi they will still be
|
||||
@@ -117,7 +125,7 @@ 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 |
|
||||
|
||||
@@ -130,3 +138,9 @@ By default the notification has a 1 second timeout that can be changed with `not
|
||||
|
||||
Furthermore, you can customize the notification messages with `notify.message`.
|
||||
For the `new` and `delete` messages, the `<key>` and `<folder>` keywords can be used, which will be replaced by the respective new/deleted bookmark's associated key and folder.
|
||||
|
||||
### `custom_desc_input`
|
||||
|
||||
When enabled, user can change description for new bookmark before it is saved.
|
||||
|
||||
By default the custom description input is filled with path.
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
--- @since 25.2.7
|
||||
-- stylua: ignore
|
||||
local SUPPORTED_KEYS = {
|
||||
{ on = "0"}, { on = "1"}, { on = "2"}, { on = "3"}, { on = "4"},
|
||||
@@ -89,27 +90,44 @@ local _save_state = ya.sync(function(state, bookmarks)
|
||||
ps.pub_to(0, "@bookmarks", save_state)
|
||||
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)
|
||||
end
|
||||
local _load_last = ya.sync(function(state)
|
||||
ps.sub_remote("@bookmarks-last", function(body)
|
||||
state.last_dir = body
|
||||
|
||||
ps.sub("cd", function()
|
||||
if state.last_mode ~= "dir" then
|
||||
ps.unsub_remote("@bookmarks-last")
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
local _save_last = ya.sync(function(state, persist, imediate)
|
||||
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 = {
|
||||
local curr = {
|
||||
on = "'",
|
||||
desc = _generate_description(file),
|
||||
path = tostring(file.url),
|
||||
is_parent = file.is_parent,
|
||||
}
|
||||
|
||||
if imediate then
|
||||
state.curr_dir = nil
|
||||
state.last_dir = curr
|
||||
else
|
||||
state.last_dir = state.curr_dir
|
||||
state.curr_dir = curr
|
||||
end
|
||||
|
||||
if persist and state.last_dir then
|
||||
ps.pub_to(0, "@bookmarks-last", state.last_dir)
|
||||
end
|
||||
end)
|
||||
|
||||
local get_last_mode = ya.sync(function(state) return state.last_mode end)
|
||||
|
||||
local save_last_dir = ya.sync(function(state)
|
||||
ps.sub("cd", function() _save_last(state.last_persist, false) end)
|
||||
|
||||
ps.sub("hover", function()
|
||||
local file = _get_bookmark_file()
|
||||
state.curr_dir.desc = _generate_description(file)
|
||||
@@ -117,11 +135,17 @@ local _save_last_directory = ya.sync(function(state, persist)
|
||||
end)
|
||||
end)
|
||||
|
||||
local save_last_jump = ya.sync(function(state) _save_last(state.last_persist, true) end)
|
||||
|
||||
local save_last_mark = ya.sync(function(state) _save_last(state.last_persist, true) end)
|
||||
|
||||
local _is_custom_desc_input_enabled = ya.sync(function(state) return state.custom_desc_input end)
|
||||
|
||||
-- ***********************************************
|
||||
-- **============= C O M M A N D S =============**
|
||||
-- ***********************************************
|
||||
|
||||
local save_bookmark = ya.sync(function(state, idx)
|
||||
local save_bookmark = ya.sync(function(state, idx, custom_desc)
|
||||
local file = _get_bookmark_file()
|
||||
|
||||
state.bookmarks = state.bookmarks or {}
|
||||
@@ -131,9 +155,14 @@ local save_bookmark = ya.sync(function(state, idx)
|
||||
_idx = #state.bookmarks + 1
|
||||
end
|
||||
|
||||
local bookmark_desc = tostring(file.url)
|
||||
if custom_desc then
|
||||
bookmark_desc = tostring(custom_desc)
|
||||
end
|
||||
|
||||
state.bookmarks[_idx] = {
|
||||
on = SUPPORTED_KEYS[idx].on,
|
||||
desc = _generate_description(file),
|
||||
desc = bookmark_desc,
|
||||
path = tostring(file.url),
|
||||
is_parent = file.is_parent,
|
||||
}
|
||||
@@ -170,6 +199,10 @@ local save_bookmark = ya.sync(function(state, idx)
|
||||
message, _ = message:gsub("<folder>", state.bookmarks[_idx].desc)
|
||||
_send_notification(message)
|
||||
end
|
||||
|
||||
if get_last_mode() == "mark" then
|
||||
save_last_mark()
|
||||
end
|
||||
end)
|
||||
|
||||
local all_bookmarks = ya.sync(function(state, append_last_dir)
|
||||
@@ -216,11 +249,8 @@ local delete_all_bookmarks = ya.sync(function(state)
|
||||
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
|
||||
@@ -228,6 +258,19 @@ return {
|
||||
if action == "save" then
|
||||
local key = ya.which { cands = SUPPORTED_KEYS, silent = true }
|
||||
if key then
|
||||
if _is_custom_desc_input_enabled() then
|
||||
local value, event = ya.input {
|
||||
title = "Save with custom description:",
|
||||
position = { "top-center", y = 3, w = 60 },
|
||||
value = tostring(_get_bookmark_file().url),
|
||||
}
|
||||
if event ~= 1 then
|
||||
return
|
||||
end
|
||||
|
||||
save_bookmark(key, value)
|
||||
return
|
||||
end
|
||||
save_bookmark(key)
|
||||
end
|
||||
return
|
||||
@@ -244,6 +287,10 @@ return {
|
||||
end
|
||||
|
||||
if action == "jump" then
|
||||
if get_last_mode() == "jump" then
|
||||
save_last_jump()
|
||||
end
|
||||
|
||||
if bookmarks[selected].is_parent then
|
||||
ya.manager_emit("cd", { bookmarks[selected].path })
|
||||
else
|
||||
@@ -258,12 +305,28 @@ 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
|
||||
_save_last_directory(args.last_directory.persist)
|
||||
if args.last_directory.mode == "mark" then
|
||||
state.last_persist = args.last_directory.persist
|
||||
state.last_mode = "mark"
|
||||
elseif args.last_directory.mode == "jump" then
|
||||
state.last_persist = args.last_directory.persist
|
||||
state.last_mode = "jump"
|
||||
elseif args.last_directory.mode == "dir" then
|
||||
state.last_persist = args.last_directory.persist
|
||||
state.last_mode = "dir"
|
||||
save_last_dir()
|
||||
else
|
||||
-- default
|
||||
state.last_persist = args.last_directory.persist
|
||||
state.last_mode = "dir"
|
||||
save_last_dir()
|
||||
end
|
||||
|
||||
if args.last_directory.persist then
|
||||
_load_last()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -284,6 +347,10 @@ return {
|
||||
state.file_pick_mode = "hover"
|
||||
end
|
||||
|
||||
if type(args.custom_desc_input) == "boolean" then
|
||||
state.custom_desc_input = args.custom_desc_input
|
||||
end
|
||||
|
||||
state.notify = {
|
||||
enable = false,
|
||||
timeout = 1,
|
||||
Reference in New Issue
Block a user