added new persistent mode
This commit is contained in:
10
README.md
10
README.md
@@ -52,7 +52,7 @@ The following are the default configurations:
|
|||||||
-- ~/.config/yazi/init.lua
|
-- ~/.config/yazi/init.lua
|
||||||
require("bookmarks"):setup({
|
require("bookmarks"):setup({
|
||||||
save_last_directory = false,
|
save_last_directory = false,
|
||||||
persist = false,
|
persist = "none",
|
||||||
notify = {
|
notify = {
|
||||||
enable = false,
|
enable = false,
|
||||||
timeout = 1,
|
timeout = 1,
|
||||||
@@ -75,6 +75,14 @@ the last directory.
|
|||||||
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
|
||||||
present.
|
present.
|
||||||
|
|
||||||
|
There are three possible values for this option:
|
||||||
|
|
||||||
|
| Value | Description |
|
||||||
|
| ------ | ---------------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| `none` | The default value, i.e., no persistance |
|
||||||
|
| `all` | All the bookmarks are saved in persistent memory |
|
||||||
|
| `vim` | This mode emulates the vim global marks, i.e., only the bookmarks in upper case (A-Z) are saved to persistent memory |
|
||||||
|
|
||||||
### `notify`
|
### `notify`
|
||||||
|
|
||||||
When enabled, notifications will be shown when the user creates a new bookmark and deletes one or
|
When enabled, notifications will be shown when the user creates a new bookmark and deletes one or
|
||||||
|
|||||||
26
init.lua
26
init.lua
@@ -37,9 +37,27 @@ local _persist_bookmarks = ya.sync(function(state)
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local _save_bookmark = ya.sync(function(_, bookmarks)
|
local _save_bookmark = ya.sync(function(state, bookmarks)
|
||||||
ya.err("Save Bookmark")
|
ya.err("Save Bookmark")
|
||||||
ps.pub_static(10, "bookmarks", bookmarks)
|
if not bookmarks then
|
||||||
|
ps.pub_static(10, "bookmarks", nil)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if state.persist == "all" then
|
||||||
|
ps.pub_static(10, "bookmarks", bookmarks)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- VIM mode
|
||||||
|
local save_bookmarks = {}
|
||||||
|
for _, value in pairs(bookmarks) do
|
||||||
|
-- Only save bookmarks in upper case keys
|
||||||
|
if string.match(value.on, "%u") then
|
||||||
|
table.insert(save_bookmarks, value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
ps.pub_static(10, "bookmarks", save_bookmarks)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local _save_last_directory = ya.sync(function(state)
|
local _save_last_directory = ya.sync(function(state)
|
||||||
@@ -177,8 +195,8 @@ return {
|
|||||||
_save_last_directory()
|
_save_last_directory()
|
||||||
end
|
end
|
||||||
|
|
||||||
if args.persist then
|
if args.persist == "all" or args.persist == "vim" then
|
||||||
state.persist = true
|
state.persist = args.persist
|
||||||
_persist_bookmarks()
|
_persist_bookmarks()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user