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

Tips: GitHub browse and Switch-create Tabs #179

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
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
44 changes: 44 additions & 0 deletions docs/tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,30 @@ run = "plugin smart-tab"
desc = "Create a tab and enter the hovered directory"
```

## Switch & create tabs: {#switch-create-tab}

Save these lines as `~/.config/yazi/plugins/switch-create-tab.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

return { entry = entry }
```

Then bind it for <kbd>2</kbd> key or any number key, in your `keymap.toml`:

```toml
[[manager.prepend_keymap]]
on = [ "2" ]
run = "plugin --sync switch-create-tab --args=1"
desc = "Create a new tab using the current path and switch to it"
```

## 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 Expand Up @@ -210,6 +234,26 @@ run = '''

Credits to [@aidanzhai for sharing it](https://t.me/yazi_rs/3325/15373) in Yazi's telegram group.

## Browse hovered file or directory in Git repository on Github {#browse-on-github}

```toml
[[manager.prepend_keymap]]
on = [ "g", "b"]
run = '''
shell 'gh browse .'
desc = "Browse cwd on Github."
'''

[[manager.prepend_keymap]]
on = [ "g", "f"]
run = '''
shell 'gh browse $(git ls-files $0) --branch=$(git branch --show-current)'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why $(git ls-files $0) and --branch=$(git branch --show-current) is needed here?

Copy link
Contributor Author

@AnirudhG07 AnirudhG07 Dec 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well if you just do gh browse wherever you are in the repo, it will open the https://github.com/name/repo_name instead of location of file.
And branch is required since if not mentioned, it will always go to main/master branch even if you are in some other branch locally in yazi.
That's why the above keybinding will simply open the exact location of the file. Hope its clear :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that you mention it, I think you should have branch for the 2nd keybinding I mentioned.
But it would be create to combine both of them into 1, since "gf" doesnt work for hovered directory.

'''
desc = "Browse hovered file on Github."
```

Browse hovered file/directory inside Git repository using [gh](https://cli.github.com/manual/gh_browse) on Github.

## Unix: Add subtitle to the running MPV {#mpv-subtitle}

Add these lines to your `~/.config/yazi/yazi.toml`:
Expand Down