2021-10-16 03:03:56 +00:00
|
|
|
# Writing Plugins
|
2021-06-24 03:33:28 +00:00
|
|
|
|
2021-07-03 09:24:37 +00:00
|
|
|
Anyone who can write [Lua][1] code, can write xplr plugins.
|
2021-06-24 03:33:28 +00:00
|
|
|
|
|
|
|
Just follow the instructions and best practices:
|
|
|
|
|
2021-10-16 03:03:56 +00:00
|
|
|
## Naming
|
2021-06-24 03:33:28 +00:00
|
|
|
|
|
|
|
xplr plugins are named using hiphen (`-`) separated words that may also include
|
|
|
|
integers. They will be plugged using the `require()` function in Lua.
|
|
|
|
|
2021-10-16 03:03:56 +00:00
|
|
|
## Structure
|
2021-06-24 03:33:28 +00:00
|
|
|
|
|
|
|
A minimal plugin should confirm to the following structure:
|
|
|
|
|
|
|
|
```
|
2022-05-23 05:27:48 +00:00
|
|
|
.
|
2021-06-24 03:33:28 +00:00
|
|
|
├── README.md
|
2022-01-19 11:00:42 +00:00
|
|
|
└── init.lua
|
2021-06-24 03:33:28 +00:00
|
|
|
```
|
|
|
|
|
2022-10-24 13:50:38 +00:00
|
|
|
You can also use [this template][2].
|
2021-06-24 03:33:28 +00:00
|
|
|
|
|
|
|
### README.md
|
|
|
|
|
|
|
|
This is where you document what the plugin does, how to use it, etc.
|
|
|
|
|
2022-01-19 11:00:42 +00:00
|
|
|
### init.lua
|
2021-06-24 03:33:28 +00:00
|
|
|
|
|
|
|
This file is executed to load the plugin. It should expose a `setup()`
|
|
|
|
function, which will be used by the users to setup the plugin.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
```lua
|
|
|
|
local function setup(args)
|
|
|
|
local xplr = xplr
|
|
|
|
-- do stuff with xplr
|
|
|
|
end
|
|
|
|
|
|
|
|
return { setup = setup }
|
|
|
|
```
|
|
|
|
|
2021-10-16 03:03:56 +00:00
|
|
|
## Publishing
|
2021-06-24 03:33:28 +00:00
|
|
|
|
2021-06-24 05:09:30 +00:00
|
|
|
When publishing plugins on GitHub or other repositories, it's a best practice
|
2021-06-24 03:33:28 +00:00
|
|
|
to append `.xplr` to the name to make them distinguishable. Similar to the
|
2021-07-03 09:24:37 +00:00
|
|
|
`*.nvim` naming convention for [Neovim][3] plugins.
|
2021-06-24 03:33:28 +00:00
|
|
|
|
2021-06-28 03:58:42 +00:00
|
|
|
Finally, after publishing, don't hesitate to
|
2021-07-03 09:24:37 +00:00
|
|
|
[let us know][4].
|
2021-06-28 03:58:42 +00:00
|
|
|
|
2022-10-24 13:50:38 +00:00
|
|
|
## Best practices
|
|
|
|
|
|
|
|
- Try not to execute a lot of commands at startup, it may make xplr slow to
|
|
|
|
start.
|
|
|
|
- When executing commands, prefer `Call0` over `Call`, `BashExec0` over
|
|
|
|
`BashExec` and so on. File names may contain newline characters
|
|
|
|
(e.g. `foo$'\n'bar`).
|
2022-10-25 14:01:06 +00:00
|
|
|
- File names may also contain quotes. Avoid writing directly to
|
|
|
|
`$XPLR_PIPE_MSG_IN`. Use `xplr -m` / `xplr --pipe-msg-in` instead.
|
2022-10-24 13:50:38 +00:00
|
|
|
- Check for empty variables using the syntax `${FOO:?}` or use a default value
|
|
|
|
`${FOO:-defaultvalue}`.
|
|
|
|
|
2021-10-16 03:03:56 +00:00
|
|
|
## Examples
|
2021-06-24 03:33:28 +00:00
|
|
|
|
2021-07-03 09:24:37 +00:00
|
|
|
Visit [Awesome Plugins][5] for xplr plugin examples.
|
|
|
|
|
2021-10-16 03:03:56 +00:00
|
|
|
## Also See
|
2021-08-27 03:25:46 +00:00
|
|
|
|
2021-10-30 02:22:42 +00:00
|
|
|
- [Tip: A list of hacks yet to make it as Lua plugins][15]
|
|
|
|
- [Tip: Some UI and themeing tips][12]
|
|
|
|
- [Tip: A list of handy utility functions][13]
|
|
|
|
- [Tip: Share tips and tricks working with Lua][14]
|
2021-08-27 03:28:38 +00:00
|
|
|
- [Tutorial: Adding a New Mode][6]
|
|
|
|
- [Example: Using Environment Variables and Pipes][7]
|
|
|
|
- [Example: Using Lua Function Calls][8]
|
2021-10-05 11:46:47 +00:00
|
|
|
- [Example: Defining Custom Layout][9]
|
|
|
|
- [Example: Customizing Table Renderer][10]
|
|
|
|
- [Example: Render a custom dynamic table][11]
|
2021-08-27 03:25:46 +00:00
|
|
|
|
2021-10-16 03:03:56 +00:00
|
|
|
[1]: https://www.lua.org
|
|
|
|
[2]: https://github.com/sayanarijit/plugin-template1.xplr
|
|
|
|
[3]: https://neovim.io
|
|
|
|
[4]: https://github.com/sayanarijit/xplr/discussions/categories/show-and-tell
|
|
|
|
[5]: awesome-plugins.md
|
2021-11-05 07:36:13 +00:00
|
|
|
[6]: configure-key-bindings.md#tutorial-adding-a-new-mode
|
2022-02-27 08:40:17 +00:00
|
|
|
[7]: environment-variables-and-pipes.md#example-using-environment-variables-and-pipes
|
|
|
|
[8]: lua-function-calls.md#example-using-lua-function-calls
|
|
|
|
[9]: layout.md#example-defining-custom-layout
|
2021-10-16 03:03:56 +00:00
|
|
|
[10]: column-renderer.md#example-customizing-table-renderer
|
2022-02-27 08:40:17 +00:00
|
|
|
[11]: layout.md#example-render-a-custom-dynamic-table
|
2021-10-30 02:22:42 +00:00
|
|
|
[12]: https://github.com/sayanarijit/xplr/discussions/274
|
|
|
|
[13]: https://github.com/sayanarijit/xplr/discussions/273
|
|
|
|
[14]: https://github.com/sayanarijit/xplr/discussions/250
|
|
|
|
[15]: https://github.com/sayanarijit/xplr/wiki/Hacks
|