From a61c08983c63a1097cd87500618fbeefa3e30cff Mon Sep 17 00:00:00 2001 From: hankertrix <91734413+hankertrix@users.noreply.github.com> Date: Thu, 26 Dec 2024 11:44:04 +0000 Subject: [PATCH 1/4] docs: add smart tab switch tip --- docs/tips.md | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/docs/tips.md b/docs/tips.md index 93ca2f16..97b9d1a8 100644 --- a/docs/tips.md +++ b/docs/tips.md @@ -98,9 +98,9 @@ desc = "Paste into the hovered directory or CWD" -## Smart tab: create a tab and enter the hovered directory {#smart-tab} +## Smart tab create: create a tab and enter the hovered directory {#smart-tab-create} -Save these lines as `~/.config/yazi/plugins/smart-tab.yazi/init.lua`: +Save these lines as `~/.config/yazi/plugins/smart-tab-create.yazi/init.lua`: ```lua --- @sync entry @@ -112,15 +112,40 @@ return { } ``` -Then bind it for t key, in your `keymap.toml`: +Then bind it to the t key, in your `keymap.toml`: ```toml [[manager.prepend_keymap]] on = "t" -run = "plugin smart-tab" +run = "plugin smart-tab-create" desc = "Create a tab and enter the hovered directory" ``` +## Smart tab switch: create tab if the tab being switched to does not exist {#smart-tab-switch} + +Save these lines as `~/.config/yazi/plugins/smart-tab-switch.yazi/init.lua`: + +```lua +local function entry(_, args) + for _ = #cx.tabs, args[1] do + ya.manager_emit("tab_create", { current = true }) + end + ya.manager_emit("tab_switch", { args[1] }) +end + +--- @sync entry +return { entry = entry } +``` + +Then bind it to the 2 key, in your `keymap.toml`: + +```toml +[[manager.prepend_keymap]] +on = "2" +run = "plugin smart-tab-switch --args=1" +desc = "Switch and create tab if it doesn't exist" +``` + ## Folder-specific rules {#folder-rules} You can subscribe to directory change events through the [`cd` event provided by DDS](/docs/dds#cd), and then do any action you want, such as setting different sorting methods for specific directories. From 9c36c6b6fa56b6714e8d400b12ae47ff0d07e442 Mon Sep 17 00:00:00 2001 From: hankertrix <91734413+hankertrix@users.noreply.github.com> Date: Thu, 26 Dec 2024 14:31:37 +0000 Subject: [PATCH 2/4] docs: keep original name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 三咲雅 · Misaki Masa --- docs/tips.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/tips.md b/docs/tips.md index 97b9d1a8..6388c97f 100644 --- a/docs/tips.md +++ b/docs/tips.md @@ -98,7 +98,7 @@ desc = "Paste into the hovered directory or CWD" -## Smart tab create: create a tab and enter the hovered directory {#smart-tab-create} +## Smart tab: create a tab and enter the hovered directory {#smart-tab} Save these lines as `~/.config/yazi/plugins/smart-tab-create.yazi/init.lua`: @@ -121,7 +121,7 @@ run = "plugin smart-tab-create" desc = "Create a tab and enter the hovered directory" ``` -## Smart tab switch: create tab if the tab being switched to does not exist {#smart-tab-switch} +## Smart tab switch: create tab if the tab being switched to does not exist {#smart-switch} Save these lines as `~/.config/yazi/plugins/smart-tab-switch.yazi/init.lua`: From ad294d0af66ed229f9dc80fb9a6101888f389750 Mon Sep 17 00:00:00 2001 From: hankertrix <91734413+hankertrix@users.noreply.github.com> Date: Thu, 26 Dec 2024 14:35:33 +0000 Subject: [PATCH 3/4] docs: place @sync directive at the head of the file --- docs/tips.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tips.md b/docs/tips.md index 6388c97f..902771b3 100644 --- a/docs/tips.md +++ b/docs/tips.md @@ -126,6 +126,7 @@ desc = "Create a tab and enter the hovered directory" Save these lines as `~/.config/yazi/plugins/smart-tab-switch.yazi/init.lua`: ```lua +--- @sync entry local function entry(_, args) for _ = #cx.tabs, args[1] do ya.manager_emit("tab_create", { current = true }) @@ -133,7 +134,6 @@ local function entry(_, args) ya.manager_emit("tab_switch", { args[1] }) end ---- @sync entry return { entry = entry } ``` From c198b890655feca9480a380c9abe21ceb396717f Mon Sep 17 00:00:00 2001 From: sxyazi Date: Fri, 27 Dec 2024 17:48:50 +0800 Subject: [PATCH 4/4] Reword --- docs/tips.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/tips.md b/docs/tips.md index 902771b3..a0f5ff03 100644 --- a/docs/tips.md +++ b/docs/tips.md @@ -100,7 +100,7 @@ desc = "Paste into the hovered directory or CWD" ## Smart tab: create a tab and enter the hovered directory {#smart-tab} -Save these lines as `~/.config/yazi/plugins/smart-tab-create.yazi/init.lua`: +Save these lines as `~/.config/yazi/plugins/smart-tab.yazi/init.lua`: ```lua --- @sync entry @@ -117,13 +117,13 @@ Then bind it to the t key, in your `keymap.toml`: ```toml [[manager.prepend_keymap]] on = "t" -run = "plugin smart-tab-create" +run = "plugin smart-tab" desc = "Create a tab and enter the hovered directory" ``` -## Smart tab switch: create tab if the tab being switched to does not exist {#smart-switch} +## Smart switch: create tab if the tab being switched to does not exist {#smart-switch} -Save these lines as `~/.config/yazi/plugins/smart-tab-switch.yazi/init.lua`: +Save these lines as `~/.config/yazi/plugins/smart-switch.yazi/init.lua`: ```lua --- @sync entry @@ -142,8 +142,8 @@ Then bind it to the 2 key, in your `keymap.toml`: ```toml [[manager.prepend_keymap]] on = "2" -run = "plugin smart-tab-switch --args=1" -desc = "Switch and create tab if it doesn't exist" +run = "plugin smart-switch --args=1" +desc = "Switch or create tab 2" ``` ## Folder-specific rules {#folder-rules}