diff --git a/init.lua b/init.lua index 5be7e67..6104584 100644 --- a/init.lua +++ b/init.lua @@ -25,12 +25,12 @@ local save_bookmark = ya.sync(function(state, idx) } if state.notify.enable then - local description = state.notify.format - description, _ = description:gsub("", SUPPORTED_KEYS[idx].on) - description, _ = description:gsub("", tostring(folder.cwd)) + local message = state.notify.message.new + message, _ = message:gsub("", SUPPORTED_KEYS[idx].on) + message, _ = message:gsub("", tostring(folder.cwd)) ya.notify { title = "Bookmarks", - content = description, + content = message, timeout = state.notify.timeout, } end @@ -38,9 +38,32 @@ end) local all_bookmarks = ya.sync(function(state) return state.bookmarks or {} end) -local delete_bookmark = ya.sync(function(state, idx) table.remove(state.bookmarks, idx) end) +local delete_bookmark = ya.sync(function(state, idx) + if state.notify.enable then + 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, + } + end -local delete_all_bookmarks = ya.sync(function(state) state.bookmarks = nil end) + table.remove(state.bookmarks, idx) +end) + +local delete_all_bookmarks = ya.sync(function(state) + state.bookmarks = nil + + if state.notify.enable then + ya.notify { + title = "Bookmarks", + content = state.notify.message.delete_all, + timeout = state.notify.timeout, + } + end +end) return { entry = function(_, args) @@ -80,16 +103,32 @@ return { return end - state.notify = { enable = false, timeout = 2, format = "New bookmark in '' -> ''" } - if args.notify ~= nil then + state.notify = { + enable = false, + timeout = 1, + message = { + new = "New bookmark '' -> ''", + delete = "Deleted bookmark in ''", + delete_all = "Deleted all bookmarks", + }, + } + if type(args.notify) == "table" then if type(args.notify.enable) == "boolean" then state.notify.enable = args.notify.enable end if type(args.notify.timeout) == "number" then state.notify.timeout = args.notify.timeout end - if type(args.notify.format) == "string" then - state.notify.format = args.notify.format + if type(args.notify.message) == "table" then + if type(args.notify.message.new) == "string" then + state.notify.message.new = args.notify.message.new + end + if type(args.notify.message.delete) == "string" then + state.notify.message.delete = args.notify.message.delete + end + if type(args.notify.message.delete_all) == "string" then + state.notify.message.delete_all = args.notify.message.delete_all + end end end end,