From 60a7357c374ec17c14eaf17e316ce39ce270f851 Mon Sep 17 00:00:00 2001 From: Diogo Duarte Date: Fri, 19 Apr 2024 03:51:23 +0100 Subject: [PATCH] organize the code --- init.lua | 72 ++++++++++++++++++++++++++------------------------------ 1 file changed, 34 insertions(+), 38 deletions(-) diff --git a/init.lua b/init.lua index 44cc73b..203b200 100644 --- a/init.lua +++ b/init.lua @@ -14,6 +14,37 @@ local SUPPORTED_KEYS = { { 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 folder = Folder:by_kind(Folder.CURRENT) @@ -35,11 +66,7 @@ local save_bookmark = ya.sync(function(state, idx) local message = state.notify.message.new message, _ = message:gsub("", SUPPORTED_KEYS[idx].on) message, _ = message:gsub("", tostring(folder.cwd)) - ya.notify { - title = "Bookmarks", - content = message, - timeout = state.notify.timeout, - } + _send_notification(message) end end) @@ -64,11 +91,7 @@ local delete_bookmark = ya.sync(function(state, idx) local message = state.notify.message.delete message, _ = message:gsub("", state.bookmarks[idx].on) message, _ = message:gsub("", state.bookmarks[idx].desc) - ya.notify { - title = "Bookmarks", - content = message, - timeout = state.notify.timeout, - } + _send_notification(message) end table.remove(state.bookmarks, idx) @@ -78,37 +101,10 @@ local delete_all_bookmarks = ya.sync(function(state) state.bookmarks = nil if state.notify and state.notify.enable then - ya.notify { - title = "Bookmarks", - content = state.notify.message.delete_all, - timeout = state.notify.timeout, - } + _send_notification(state.notify.message.delete_all) 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 { entry = function(_, args) local action = args[1]