organize the code
This commit is contained in:
72
init.lua
72
init.lua
@@ -14,6 +14,37 @@ local SUPPORTED_KEYS = {
|
|||||||
{ on = "u"}, { on = "v"}, { on = "w"}, { on = "x"}, { on = "y"}, { on = "z"},
|
{ on = "u"}, { on = "v"}, { on = "w"}, { on = "x"}, { on = "y"}, { on = "z"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local _send_notification = ya.sync(
|
||||||
|
function(state, message)
|
||||||
|
ya.notify {
|
||||||
|
title = "Bookmarks",
|
||||||
|
content = message,
|
||||||
|
timeout = state.notify.timeout,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
)
|
||||||
|
|
||||||
|
local _save_last_directory = ya.sync(function(state)
|
||||||
|
ps.sub("cd", function()
|
||||||
|
local folder = Folder:by_kind(Folder.CURRENT)
|
||||||
|
state.last_dir = state.curr_dir
|
||||||
|
state.curr_dir = {
|
||||||
|
on = "'",
|
||||||
|
desc = tostring(folder.cwd),
|
||||||
|
cursor = folder.cursor,
|
||||||
|
}
|
||||||
|
end)
|
||||||
|
|
||||||
|
ps.sub("hover", function()
|
||||||
|
local folder = Folder:by_kind(Folder.CURRENT)
|
||||||
|
state.curr_dir.cursor = folder.cursor
|
||||||
|
end)
|
||||||
|
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)
|
||||||
local folder = Folder:by_kind(Folder.CURRENT)
|
local folder = Folder:by_kind(Folder.CURRENT)
|
||||||
|
|
||||||
@@ -35,11 +66,7 @@ local save_bookmark = ya.sync(function(state, idx)
|
|||||||
local message = state.notify.message.new
|
local message = state.notify.message.new
|
||||||
message, _ = message:gsub("<key>", SUPPORTED_KEYS[idx].on)
|
message, _ = message:gsub("<key>", SUPPORTED_KEYS[idx].on)
|
||||||
message, _ = message:gsub("<folder>", tostring(folder.cwd))
|
message, _ = message:gsub("<folder>", tostring(folder.cwd))
|
||||||
ya.notify {
|
_send_notification(message)
|
||||||
title = "Bookmarks",
|
|
||||||
content = message,
|
|
||||||
timeout = state.notify.timeout,
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -64,11 +91,7 @@ local delete_bookmark = ya.sync(function(state, idx)
|
|||||||
local message = state.notify.message.delete
|
local message = state.notify.message.delete
|
||||||
message, _ = message:gsub("<key>", state.bookmarks[idx].on)
|
message, _ = message:gsub("<key>", state.bookmarks[idx].on)
|
||||||
message, _ = message:gsub("<folder>", state.bookmarks[idx].desc)
|
message, _ = message:gsub("<folder>", state.bookmarks[idx].desc)
|
||||||
ya.notify {
|
_send_notification(message)
|
||||||
title = "Bookmarks",
|
|
||||||
content = message,
|
|
||||||
timeout = state.notify.timeout,
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
table.remove(state.bookmarks, idx)
|
table.remove(state.bookmarks, idx)
|
||||||
@@ -78,37 +101,10 @@ local delete_all_bookmarks = ya.sync(function(state)
|
|||||||
state.bookmarks = nil
|
state.bookmarks = nil
|
||||||
|
|
||||||
if state.notify and state.notify.enable then
|
if state.notify and state.notify.enable then
|
||||||
ya.notify {
|
_send_notification(state.notify.message.delete_all)
|
||||||
title = "Bookmarks",
|
|
||||||
content = state.notify.message.delete_all,
|
|
||||||
timeout = state.notify.timeout,
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local _save_last_directory = ya.sync(function(state)
|
|
||||||
state.curr_dir = {
|
|
||||||
on = "'",
|
|
||||||
desc = "~",
|
|
||||||
cursor = 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
ps.sub("cd", function()
|
|
||||||
local folder = Folder:by_kind(Folder.CURRENT)
|
|
||||||
state.last_dir = state.curr_dir
|
|
||||||
state.curr_dir = {
|
|
||||||
on = "'",
|
|
||||||
desc = tostring(folder.cwd),
|
|
||||||
cursor = folder.cursor,
|
|
||||||
}
|
|
||||||
end)
|
|
||||||
|
|
||||||
ps.sub("hover", function()
|
|
||||||
local folder = Folder:by_kind(Folder.CURRENT)
|
|
||||||
state.curr_dir.cursor = folder.cursor
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
entry = function(_, args)
|
entry = function(_, args)
|
||||||
local action = args[1]
|
local action = args[1]
|
||||||
|
|||||||
Reference in New Issue
Block a user