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

Command aliases #1800

Open
sxyazi opened this issue Oct 17, 2024 · 2 comments
Open

Command aliases #1800

sxyazi opened this issue Oct 17, 2024 · 2 comments
Labels
RFC Request for Comments

Comments

@sxyazi
Copy link
Owner

sxyazi commented Oct 17, 2024

This proposal aims to introduce the concept of command aliases to simplify existing shell and plugin commands.

Alias commands are treated as special command markers, with everything following the marker considered parameters for the actual command. This allows:

{ on = "<C-t>", run = """
  shell 'echo "Hello world"' --confirm
""" }

to be rewritten as:

{ on = "<C-t>", run = '; echo "Hello world"' }

Here, the ; marker represents shell '...' --confirm. Similarly, it enables:

{ on = "<C-t>", run = """
  plugin --sync my-plugin --args='--foo "bar baz"'
""" }

to be written as:

{ on = "<C-t>", run = '! my-plugin --foo "bar baz"' }

In this case, the ! marker stands for plugin --sync ... --args='...', greatly simplifying command writing.

Note that the ; and ! markers are not final and require further discussion — such as whether to use ;; or !! instead of a single character. Also, we need to determine which marker to use for commands like shell --confirm 'ya pub dds-cd --str "/tmp"', one possible way is:

{ on = "<C-t>", run = "@ dds-cd /tmp" }

We also need to consider a separate marker for async plugins, i.e., just plugin without --sync.

@sxyazi sxyazi added the RFC Request for Comments label Oct 17, 2024
@AnirudhG07
Copy link

AnirudhG07 commented Oct 23, 2024

For the shell command, how would you go about using $0, $@?

@boydaihungst
Copy link

boydaihungst commented Oct 24, 2024

For readability, this is not a good idea. Instead, we could change run to run_shell, run_plugin, run_cmd (or keep run for better backward compatibility). Additionally, the run in keymap.toml and yazi.toml (opener, fetcher, preloader, previewer) serve different purposes but use the same name. We should also update them for clarity.

keymap.toml

Shell commands

We only need interactive as true or false, and can remove confirm. Interactive = false is default.

We can also specify which shell to use for running the script.
Edit the shell script in Vim is also much easier(combo ci' then enter new script)

keymap = [
  { on = "<C-t>", run_shell = 'echo "Hello world"', block = true, orphan = true, interactive = false, cursor = 1, shell = "fish" },
  { on = "<C-t>", run_shell = 'echo "Hello world"', block = true, orphan = true, interactive = false, cursor = 1 },

Built-in and custom plugins

Using sync = true makes sense, as this syntax is already used in preloaders.

keymap = [
  { on = "<C-t>", run_plugin = 'smart-enter  --foo "bar baz"' },
  { on = "<C-t>", run_plugin = 'hide-preview  --foo "bar baz"', sync = true },
]

Built-in Yazi Commands

We can either keep it as run for better backward compatibility or change it to run_cmd for better readability.

keymap = [
  { on = "O", run = "open --interactive", desc = "Show task manager" },
  { on = "O", run_cmd = "open --interactive", desc = "Show task manager" },
]

yazi.toml

Opener with.

[opener]
  play = [{ with = 'vlc "$@"' }]
  ebook = [{ with = 'ebook_viewer "$@"' }]

Preloader with_plugin

preloaders = [
  { mime = "application/pdf", with_plugin = "pdf" },
]

Previewer with_plugin

previewers = [
    { name = "*/", with_plugin = "folder", sync = true },
]

Fetcher from_plugin

fetchers = [
  { id = "mime", name = "*", from_plugin = "mime-ext", if = "!mime", prio = "high" },
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Request for Comments
Projects
None yet
Development

No branches or pull requests

3 participants