From 17702a3752e15d1e7919e5aebf742a141ac56735 Mon Sep 17 00:00:00 2001 From: nralbrecht Date: Tue, 27 Aug 2024 17:43:40 +0200 Subject: [PATCH 1/5] Add option to always pick the current folder and ignore hovered folder --- init.lua | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/init.lua b/init.lua index ba22263..d6f4489 100644 --- a/init.lua +++ b/init.lua @@ -33,9 +33,10 @@ local _get_real_index = ya.sync(function(state, idx) return nil end) -local _get_hovered_file = ya.sync(function() +local _get_bookmark_file = ya.sync(function(state) local folder = cx.active.current - if not folder.hovered then + + if state.bookmark_file_pick_mode == "current" or not folder.hovered then return { url = folder.cwd, is_cwd = true } end return { url = folder.hovered.url, is_cwd = false } @@ -94,7 +95,7 @@ local _save_last_directory = ya.sync(function(state, persist) end ps.sub("cd", function() - local file = _get_hovered_file() + local file = _get_bookmark_file() state.last_dir = state.curr_dir if persist and state.last_dir then @@ -109,7 +110,7 @@ local _save_last_directory = ya.sync(function(state, persist) end) ps.sub("hover", function() - local file = _get_hovered_file() + local file = _get_bookmark_file() state.curr_dir.desc = _generate_description(file) state.curr_dir.path = tostring(file.url) end) @@ -120,7 +121,7 @@ end) -- *********************************************** local save_bookmark = ya.sync(function(state, idx) - local file = _get_hovered_file() + local file = _get_bookmark_file() state.bookmarks = state.bookmarks or {} @@ -246,6 +247,12 @@ return { state.desc_format = "full" end + if args.bookmark_file_pick_mode == "current" then + state.bookmark_file_pick_mode = "current" + else + state.bookmark_file_pick_mode = "hover" + end + state.notify = { enable = false, timeout = 1, From 53ae96aed82520ec4c672b0a6971a049331fb29d Mon Sep 17 00:00:00 2001 From: nralbrecht Date: Tue, 27 Aug 2024 20:02:38 +0200 Subject: [PATCH 2/5] Rename bookmark_file_pick_mode option value from current to parent --- init.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/init.lua b/init.lua index d6f4489..8bddb24 100644 --- a/init.lua +++ b/init.lua @@ -36,7 +36,7 @@ end) local _get_bookmark_file = ya.sync(function(state) local folder = cx.active.current - if state.bookmark_file_pick_mode == "current" or not folder.hovered then + if state.bookmark_file_pick_mode == "parent" or not folder.hovered then return { url = folder.cwd, is_cwd = true } end return { url = folder.hovered.url, is_cwd = false } @@ -247,8 +247,8 @@ return { state.desc_format = "full" end - if args.bookmark_file_pick_mode == "current" then - state.bookmark_file_pick_mode = "current" + if args.bookmark_file_pick_mode == "parent" then + state.bookmark_file_pick_mode = "parent" else state.bookmark_file_pick_mode = "hover" end From 7ef1a95da1e203df8a2a61c48c2fae1b0fc61cc1 Mon Sep 17 00:00:00 2001 From: nralbrecht Date: Tue, 27 Aug 2024 20:04:01 +0200 Subject: [PATCH 3/5] Add bookmark_file_pick_mode option to README --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index a1a259b..da01379 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ require("bookmarks"):setup({ last_directory = { enable = false, persist = false }, persist = "none", desc_format = "full", + bookmark_file_pick_mode = "hover", notify = { enable = false, timeout = 1, @@ -135,6 +136,17 @@ There are two possible values for this option: | `full` | The default, it shows the full path of the bookmark, i.e., the parent folder + the hovered file | | `parent` | Only shows the parent folder of the bookmark | +### `bookmark_file_pick_mode` + +The mode for choosing which directory to bookmark. + +There are two possible values for this option: + +| Value | Description | +| -------- | ----------------------------------------------------------------------------------------------- | +| `hover` | The default, it uses the path of the hovered file for new bookmarks | +| `parent` | Uses the path of the parent folder for new bookmarks | + ### `notify` When enabled, notifications will be shown when the user creates a new bookmark and deletes one or From 5b4258225bf2b04f9499ab57a3f3d14a5b577cd1 Mon Sep 17 00:00:00 2001 From: nralbrecht Date: Wed, 28 Aug 2024 17:18:29 +0200 Subject: [PATCH 4/5] Rename bookmark_file_pick_mode option to file_pick_mode --- README.md | 4 ++-- init.lua | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index da01379..77e929c 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ require("bookmarks"):setup({ last_directory = { enable = false, persist = false }, persist = "none", desc_format = "full", - bookmark_file_pick_mode = "hover", + file_pick_mode = "hover", notify = { enable = false, timeout = 1, @@ -136,7 +136,7 @@ There are two possible values for this option: | `full` | The default, it shows the full path of the bookmark, i.e., the parent folder + the hovered file | | `parent` | Only shows the parent folder of the bookmark | -### `bookmark_file_pick_mode` +### `file_pick_mode` The mode for choosing which directory to bookmark. diff --git a/init.lua b/init.lua index 8bddb24..2e670d0 100644 --- a/init.lua +++ b/init.lua @@ -36,7 +36,7 @@ end) local _get_bookmark_file = ya.sync(function(state) local folder = cx.active.current - if state.bookmark_file_pick_mode == "parent" or not folder.hovered then + if state.file_pick_mode == "parent" or not folder.hovered then return { url = folder.cwd, is_cwd = true } end return { url = folder.hovered.url, is_cwd = false } @@ -247,10 +247,10 @@ return { state.desc_format = "full" end - if args.bookmark_file_pick_mode == "parent" then - state.bookmark_file_pick_mode = "parent" + if args.file_pick_mode == "parent" then + state.file_pick_mode = "parent" else - state.bookmark_file_pick_mode = "hover" + state.file_pick_mode = "hover" end state.notify = { From 6769310fa2fc0ca6ce0a35de0c3eb7986af538fe Mon Sep 17 00:00:00 2001 From: nralbrecht Date: Wed, 28 Aug 2024 17:34:29 +0200 Subject: [PATCH 5/5] Change to directory if the parent is stored When storing a hovered file as bookmark it makes sense to use the reveal command to move to it. When storing the parent directory however, one has to cd to it. Otherwise the parent directory is opened and the stored directory is only focused. --- init.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/init.lua b/init.lua index 2e670d0..03a50c5 100644 --- a/init.lua +++ b/init.lua @@ -37,14 +37,14 @@ local _get_bookmark_file = ya.sync(function(state) local folder = cx.active.current if state.file_pick_mode == "parent" or not folder.hovered then - return { url = folder.cwd, is_cwd = true } + return { url = folder.cwd, is_parent = true } end - return { url = folder.hovered.url, is_cwd = false } + return { url = folder.hovered.url, is_parent = false } end) local _generate_description = ya.sync(function(state, file) -- if this is true, we don't have information about the folder, so just return the folder url - if file.is_cwd then + if file.is_parent then return tostring(file.url) end @@ -106,6 +106,7 @@ local _save_last_directory = ya.sync(function(state, persist) on = "'", desc = _generate_description(file), path = tostring(file.url), + is_parent = file.is_parent, } end) @@ -134,6 +135,7 @@ local save_bookmark = ya.sync(function(state, idx) on = SUPPORTED_KEYS[idx].on, desc = _generate_description(file), path = tostring(file.url), + is_parent = file.is_parent, } if state.persist then @@ -217,7 +219,11 @@ return { end if action == "jump" then - ya.manager_emit("reveal", { bookmarks[selected].path }) + if bookmarks[selected].is_parent then + ya.manager_emit("cd", { bookmarks[selected].path }) + else + ya.manager_emit("reveal", { bookmarks[selected].path }) + end elseif action == "delete" then delete_bookmark(selected) end