Merge branch 'main' into last_dir_mode
This commit is contained in:
@@ -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.4.0+
|
- [Yazi](https://github.com/sxyazi/yazi) v25.2.7+
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
@@ -66,6 +66,7 @@ require("bookmarks"):setup({
|
|||||||
persist = "none",
|
persist = "none",
|
||||||
desc_format = "full",
|
desc_format = "full",
|
||||||
file_pick_mode = "hover",
|
file_pick_mode = "hover",
|
||||||
|
custom_desc_input = false,
|
||||||
notify = {
|
notify = {
|
||||||
enable = false,
|
enable = false,
|
||||||
timeout = 1,
|
timeout = 1,
|
||||||
@@ -137,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`.
|
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.
|
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.
|
||||||
|
|||||||
41
main.lua
41
main.lua
@@ -1,3 +1,4 @@
|
|||||||
|
--- @since 25.2.7
|
||||||
-- stylua: ignore
|
-- stylua: ignore
|
||||||
local SUPPORTED_KEYS = {
|
local SUPPORTED_KEYS = {
|
||||||
{ on = "0"}, { on = "1"}, { on = "2"}, { on = "3"}, { on = "4"},
|
{ on = "0"}, { on = "1"}, { on = "2"}, { on = "3"}, { on = "4"},
|
||||||
@@ -125,9 +126,7 @@ end)
|
|||||||
local get_last_mode = ya.sync(function(state) return state.last_mode end)
|
local get_last_mode = ya.sync(function(state) return state.last_mode end)
|
||||||
|
|
||||||
local save_last_dir = ya.sync(function(state)
|
local save_last_dir = ya.sync(function(state)
|
||||||
ps.sub("cd", function()
|
ps.sub("cd", function() _save_last(state.last_persist, false) end)
|
||||||
_save_last(state.last_persist, false)
|
|
||||||
end)
|
|
||||||
|
|
||||||
ps.sub("hover", function()
|
ps.sub("hover", function()
|
||||||
local file = _get_bookmark_file()
|
local file = _get_bookmark_file()
|
||||||
@@ -136,19 +135,17 @@ local save_last_dir = ya.sync(function(state)
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local save_last_jump = ya.sync(function(state)
|
local save_last_jump = ya.sync(function(state) _save_last(state.last_persist, true) end)
|
||||||
_save_last(state.last_persist, true)
|
|
||||||
end)
|
|
||||||
|
|
||||||
local save_last_mark = ya.sync(function(state)
|
local save_last_mark = ya.sync(function(state) _save_last(state.last_persist, true) end)
|
||||||
_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 =============**
|
-- **============= 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()
|
local file = _get_bookmark_file()
|
||||||
|
|
||||||
state.bookmarks = state.bookmarks or {}
|
state.bookmarks = state.bookmarks or {}
|
||||||
@@ -158,9 +155,14 @@ local save_bookmark = ya.sync(function(state, idx)
|
|||||||
_idx = #state.bookmarks + 1
|
_idx = #state.bookmarks + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local bookmark_desc = tostring(file.url)
|
||||||
|
if custom_desc then
|
||||||
|
bookmark_desc = tostring(custom_desc)
|
||||||
|
end
|
||||||
|
|
||||||
state.bookmarks[_idx] = {
|
state.bookmarks[_idx] = {
|
||||||
on = SUPPORTED_KEYS[idx].on,
|
on = SUPPORTED_KEYS[idx].on,
|
||||||
desc = _generate_description(file),
|
desc = bookmark_desc,
|
||||||
path = tostring(file.url),
|
path = tostring(file.url),
|
||||||
is_parent = file.is_parent,
|
is_parent = file.is_parent,
|
||||||
}
|
}
|
||||||
@@ -256,6 +258,19 @@ return {
|
|||||||
if action == "save" then
|
if action == "save" then
|
||||||
local key = ya.which { cands = SUPPORTED_KEYS, silent = true }
|
local key = ya.which { cands = SUPPORTED_KEYS, silent = true }
|
||||||
if key then
|
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)
|
save_bookmark(key)
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
@@ -331,6 +346,10 @@ return {
|
|||||||
state.file_pick_mode = "hover"
|
state.file_pick_mode = "hover"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if type(args.custom_desc_input) == "boolean" then
|
||||||
|
state.custom_desc_input = args.custom_desc_input
|
||||||
|
end
|
||||||
|
|
||||||
state.notify = {
|
state.notify = {
|
||||||
enable = false,
|
enable = false,
|
||||||
timeout = 1,
|
timeout = 1,
|
||||||
|
|||||||
Reference in New Issue
Block a user