Merge branch 'main' of github.com:dedukun/bookmarks.yazi
This commit is contained in:
14
README.md
14
README.md
@@ -23,10 +23,10 @@ ya pack -a dedukun/bookmarks
|
|||||||
|
|
||||||
## Import/Export bookmarks
|
## Import/Export bookmarks
|
||||||
|
|
||||||
This plugin uses [Yazi's DDS](https://yazi-rs.github.io/docs/dds/) for bookmark persistence, as such,
|
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)
|
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.
|
**_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
|
## Configuration
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ The following are the default configurations:
|
|||||||
```lua
|
```lua
|
||||||
-- ~/.config/yazi/init.lua
|
-- ~/.config/yazi/init.lua
|
||||||
require("bookmarks"):setup({
|
require("bookmarks"):setup({
|
||||||
last_directory = { enable = false, persist = false },
|
last_directory = { enable = false, persist = false, mode="dir" },
|
||||||
persist = "none",
|
persist = "none",
|
||||||
desc_format = "full",
|
desc_format = "full",
|
||||||
file_pick_mode = "hover",
|
file_pick_mode = "hover",
|
||||||
@@ -86,6 +86,14 @@ the last directory.
|
|||||||
|
|
||||||
There's also the option to enable persistence to this automatic bookmark.
|
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`
|
### `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
|
||||||
|
|||||||
82
main.lua
82
main.lua
@@ -90,26 +90,43 @@ local _save_state = ya.sync(function(state, bookmarks)
|
|||||||
ps.pub_to(0, "@bookmarks", save_state)
|
ps.pub_to(0, "@bookmarks", save_state)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local _save_last_directory = ya.sync(function(state, persist)
|
local _load_last = ya.sync(function(state)
|
||||||
if persist then
|
ps.sub_remote("@bookmarks-last", function(body)
|
||||||
ps.sub_remote("@bookmarks-lastdir", function(body) state.curr_dir = body end)
|
state.last_dir = body
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
ps.sub("cd", function()
|
if persist and state.last_dir then
|
||||||
local file = _get_bookmark_file()
|
ps.pub_to(0, "@bookmarks-last", state.last_dir)
|
||||||
state.last_dir = state.curr_dir
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
if persist and state.last_dir then
|
local get_last_mode = ya.sync(function(state) return state.last_mode end)
|
||||||
ps.pub_to(0, "@bookmarks-lastdir", state.last_dir)
|
|
||||||
end
|
|
||||||
|
|
||||||
state.curr_dir = {
|
local save_last_dir = ya.sync(function(state)
|
||||||
on = "'",
|
ps.sub("cd", function() _save_last(state.last_persist, false) end)
|
||||||
desc = _generate_description(file),
|
|
||||||
path = tostring(file.url),
|
|
||||||
is_parent = file.is_parent,
|
|
||||||
}
|
|
||||||
end)
|
|
||||||
|
|
||||||
ps.sub("hover", function()
|
ps.sub("hover", function()
|
||||||
local file = _get_bookmark_file()
|
local file = _get_bookmark_file()
|
||||||
@@ -118,6 +135,10 @@ local _save_last_directory = ya.sync(function(state, persist)
|
|||||||
end)
|
end)
|
||||||
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)
|
local _is_custom_desc_input_enabled = ya.sync(function(state) return state.custom_desc_input end)
|
||||||
|
|
||||||
-- ***********************************************
|
-- ***********************************************
|
||||||
@@ -178,6 +199,10 @@ local save_bookmark = ya.sync(function(state, idx, custom_desc)
|
|||||||
message, _ = message:gsub("<folder>", state.bookmarks[_idx].desc)
|
message, _ = message:gsub("<folder>", state.bookmarks[_idx].desc)
|
||||||
_send_notification(message)
|
_send_notification(message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if get_last_mode() == "mark" then
|
||||||
|
save_last_mark()
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local all_bookmarks = ya.sync(function(state, append_last_dir)
|
local all_bookmarks = ya.sync(function(state, append_last_dir)
|
||||||
@@ -262,6 +287,10 @@ return {
|
|||||||
end
|
end
|
||||||
|
|
||||||
if action == "jump" then
|
if action == "jump" then
|
||||||
|
if get_last_mode() == "jump" then
|
||||||
|
save_last_jump()
|
||||||
|
end
|
||||||
|
|
||||||
if bookmarks[selected].is_parent then
|
if bookmarks[selected].is_parent then
|
||||||
ya.mgr_emit("cd", { bookmarks[selected].path })
|
ya.mgr_emit("cd", { bookmarks[selected].path })
|
||||||
else
|
else
|
||||||
@@ -278,7 +307,26 @@ return {
|
|||||||
|
|
||||||
if type(args.last_directory) == "table" then
|
if type(args.last_directory) == "table" then
|
||||||
if args.last_directory.enable 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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user