From 914444c097de749844b311ebb78ee7e9be31421b Mon Sep 17 00:00:00 2001 From: Diogo Duarte Date: Sun, 31 Mar 2024 15:28:55 +0100 Subject: [PATCH] started working of having '' go to last dir --- init.lua | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index 992531b..30c5dbc 100644 --- a/init.lua +++ b/init.lua @@ -43,7 +43,15 @@ local save_bookmark = ya.sync(function(state, idx) end end) -local all_bookmarks = ya.sync(function(state) return state.bookmarks or {} end) +local all_bookmarks = ya.sync(function(state, append_last_dir) + bookmarks = state.bookmarks or {} + + if append_last_dir and state.last_dir then + table.insert(bookmarks, state.last_dir) + end + + return bookmarks +end) local delete_bookmark = ya.sync(function(state, idx) if state.notify and state.notify.enable then @@ -72,6 +80,18 @@ local delete_all_bookmarks = ya.sync(function(state) end end) +local _save_last_dir = 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) +end) + return { entry = function(_, args) local action = args[1] @@ -91,7 +111,7 @@ return { return delete_all_bookmarks() end - local bookmarks = all_bookmarks() + local bookmarks = all_bookmarks(action == "jump") local selected = #bookmarks > 0 and ya.which { cands = bookmarks } if not selected then return @@ -110,6 +130,8 @@ return { return end + _save_last_dir() + state.notify = { enable = false, timeout = 1,