Skip to content

peterfication/mux.yazi

Repository files navigation

mux - Yazi plugin multiplexer

This Yazi plugin enables multiple previewers per previewer entry. One can specify the previewers to cycle through and a keybinding that triggers the cycle. It uses the args to determine which previewers to call and calls the current previewers peek and seek methods accordingly.

Credits to @sxyazi for the idea (see issue comment).

asciicast

Installation

ya pkg add peterfication/mux

Configuration

Example previewer configuration

prepend_previewers = [
  { name = "*.csv", run = "mux code file" },
  # ...
]

Example keybinding

[mgr]
prepend_keymap = [
  { on = "p", run = "mux next", desc = "Show next previewer" },
  # ...
]

Example setup (optional)

Option Default Description
notify_on_switch false Whether to show a notification when the previewer is switched.
remember_per_file_extension false If false, the current previewer is remembered per file (per session). If true, the current previewer is remembered per suffix, so e.g. each JSON file will be previewed with the last selected previewer for JSON files. NOTE: this is without mime types yet, so folders and files without an extension will be treated the same, which will lead to unexpected behavior.
aliases {} See "Use cases" for examples on how to use it.

NOTE: Setup is only required if you want to change from the defaults.

require("mux"):setup({
  notify_on_switch = true, -- Default: false
  remember_per_file_extension = true, -- Default: false
  aliases = {}, -- Default: {}
})

Use cases

eza list and tree preview

(Like with the eza-preview.yazi plugin)

NOTE: Requires the piper plugin.

Explanations:

  • cd before eza makes sure that the root does not contain the full path
  • LS_COLORS paints executables green, like yazi
-- init.lua
require("mux"):setup({
	aliases = {
		eza_tree_1 = {
			previewer = "piper",
			args = {
				'cd "$1" && LS_COLORS="ex=32" eza --oneline --tree --level 1 --color=always --icons=always --group-directories-first --no-quotes .',
			},
		},
		eza_tree_2 = {
			previewer = "piper",
			args = {
				'cd "$1" && LS_COLORS="ex=32" eza --oneline --tree --level 2 --color=always --icons=always --group-directories-first --no-quotes .',
			},
		},
		eza_tree_3 = {
			previewer = "piper",
			args = {
				'cd "$1" && LS_COLORS="ex=32" eza --oneline --tree --level 3 --color=always --icons=always --group-directories-first --no-quotes .',
			},
		},
		eza_tree_4 = {
			previewer = "piper",
			args = {
				'cd "$1" && LS_COLORS="ex=32" eza --oneline --tree --level 4 --color=always --icons=always --group-directories-first --no-quotes .',
			},
		},
	},
})
# yazi.toml
[mgr]
prepend_previewers = [
  { name = "*/", run = "mux eza_tree_1 eza_tree_2 eza_tree_3 eza_tree_4" },
  # ...
]
# keymap.toml
[mgr]
prepend_keymap = [
  # Plugin: mux
  { on = "P", run = "plugin mux next", desc = "Cycle through mux previewers" },
  # ...
]

duckdb and code previewer

NOTE: Requires the duckdb plugin.

prepend_previewers = [
  { name = "*.csv", run = "mux duckdb code" },
  { name = "*.tsv", run = "mux duckdb code" },
  { name = "*.json", run = "mux duckdb code" },
  # ...
]
# keymap.toml
[mgr]
prepend_keymap = [
  # Plugin: mux
  { on = "P", run = "plugin mux next", desc = "Cycle through mux previewers" },
  # ...
]

Roadmap

  • Support spotters
  • Support fetchers?

Development

See previewer plugin docs.

Useful just commands are defined in the Justfile.

just ci

License

This project is licensed under the MIT license (LICENSE or opensource.org/licenses/MIT)

About

Yazi previewer multiplexer

Resources

License

Stars

Watchers

Forks

Packages

No packages published