Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add smart tab switch tip #188

Merged
merged 4 commits into from
Dec 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions docs/tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ desc = "Paste into the hovered directory or CWD"
<video src="https://github.com/sxyazi/yazi/assets/17523360/080212b5-43e7-4c36-83e8-312495d50383" width="100%" controls muted></video>
</details>

## 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}
hankertrix marked this conversation as resolved.
Show resolved Hide resolved

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
Expand All @@ -112,15 +112,40 @@ return {
}
```

Then bind it for <kbd>t</kbd> key, in your `keymap.toml`:
Then bind it to the <kbd>t</kbd> 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}
hankertrix marked this conversation as resolved.
Show resolved Hide resolved

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
hankertrix marked this conversation as resolved.
Show resolved Hide resolved
return { entry = entry }
```

Then bind it to the <kbd>2</kbd> 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.
Expand Down