From 5f9236a05d783a32e21420fe37222ff9760a69b0 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Sat, 3 Feb 2024 02:59:27 +0800 Subject: [PATCH] docs: add example of how to receive arguments in a plugin --- docs/plugins/overview.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/plugins/overview.md b/docs/plugins/overview.md index 4299b9a0..cd205fcc 100644 --- a/docs/plugins/overview.md +++ b/docs/plugins/overview.md @@ -46,7 +46,21 @@ You can bind a `plugin` command to a specific key in your `keymap.toml` with: | `--sync` | Run the plugin in a sync context. | | `--args=[args]` | Shell-style arguments passed to the plugin. | -For example, `plugin test --sync --args="foo bar"` will run the `test` plugin with the arguments `foo` and `bar` in a sync context. +For example, `plugin test --sync --args='foo bar'` will run the `test` plugin with the arguments `foo` and `bar` in a sync context. + +To receive the arguments in the plugin, use `{ ... }`: + +```lua +-- ~/.config/yazi/plugins/test.yazi/init.lua +local args = { ... } + +return { + entry = function() + ya.err(args[1]) -- "foo" + ya.err(args[2]) -- "bar" + end, +} +``` ## Sync vs Async