From 0e772b951b3fc0a4943cce0203210896bb91a220 Mon Sep 17 00:00:00 2001 From: Diogo Duarte Date: Tue, 18 Feb 2025 23:02:42 +0000 Subject: [PATCH] Add custom keybinding for last + added 'jump' command --- main.lua | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/main.lua b/main.lua index 7bfa9ca..d3954a7 100644 --- a/main.lua +++ b/main.lua @@ -92,7 +92,10 @@ end) local _save_last_directory = ya.sync(function(state, persist) if persist then - ps.sub_remote("@bookmarks-lastdir", function(body) state.curr_dir = body end) + ps.sub_remote("@bookmarks-lastdir", function(body) + state.curr_dir = body + state.curr_dir.on = state.last_directory_key + end) end ps.sub("cd", function() @@ -104,7 +107,7 @@ local _save_last_directory = ya.sync(function(state, persist) end state.curr_dir = { - on = "'", + on = state.last_directory_key, desc = _generate_description(file), path = tostring(file.url), is_parent = file.is_parent, @@ -216,6 +219,14 @@ local delete_all_bookmarks = ya.sync(function(state) end end) +local jump_to_last = ya.sync(function(state) + if state.last_dir.is_parent then + ya.manager_emit("cd", { state.last_dir.is_parent }) + else + ya.manager_emit("reveal", { state.last_dir.is_parent }) + end +end) + return { entry = function(_, job) local action = job.args[1] @@ -229,10 +240,10 @@ return { save_bookmark(key) end return - end - - if action == "delete_all" then + elseif action == "delete_all" then return delete_all_bookmarks() + elseif action == "jump_last" then + return jump_to_last() end local bookmarks = all_bookmarks(action == "jump") @@ -258,6 +269,11 @@ return { if type(args.last_directory) == "table" then if args.last_directory.enable then + state.last_directory_key = "'" + if type(args.last_directory.key) == "string" then + state.last_directory_key = args.last_directory.key + end + _save_last_directory(args.last_directory.persist) end end