wez / wezterm

A GPU-accelerated cross-platform terminal emulator and multiplexer written by @wez and implemented in Rust
https://wezfurlong.org/wezterm/
Other
16.7k stars 748 forks source link

Plugin aliases to enable plugin sub modules. #5812

Open MLFlexer opened 2 months ago

MLFlexer commented 2 months ago

Is your feature request related to a problem? Please describe. As a plugin developer I would like to be able to use multiple files. This is currently not well supported, and the plugin author must do some tricks to enable this. See #4248 and #4150.

Describe the solution you'd like The ideal solution would be that I as a plugin developer or a user of the plugin is able to call require("") as i would when requiring other lua files. One way to achive this without breaking current plugins would be to add the option to alias plugins. That is, there is a directory where plugins are stored in subdirectories, with each subdirectory having the same name as the alias (plugin_identifier). Then the alias directory is added to the lua searchpath making it possible to have the descriped ideal solution, while also not breaking any existing plugins.

To add this functionality it would require:

  1. adding the alias directory I would suggest adding it as a parallel or a subdirectory of the current data/wezterm/plugins directory
  2. Adding a function call to alias a plugin This could be something like wezterm.plugin.require_aliased(<url_str>, <alias_str>). This would function closely to the other require function call, but clone the repository into the aliased directory.
  3. Update the wezterm.plugin.update_all() and wezterm.plugin.list() function calls to include aliased functions.
  4. Add the aliased directory to the lua search path.

If my thought process is correct, then I belive that I am able to implement this and I am willing to give it a shot. I could also make documentation for this, as there is no documentation for the wezterm.plugin module.

Describe alternatives you've considered I don't have any great alternatives at the moment.

Additional context Sub directory approach

data/
└── wezterm/
    └── plugins/
        └── aliases/
            ├── plugin_a
            ├── plugin_b
            ├── ...
            └── plugin_z

Parallel approach

data/
└── wezterm/
    ├── plugins
    └── aliases/
        ├── plugin_a
        ├── plugin_b
        ├── ...
        └── plugin_z
MLFlexer commented 2 months ago

A third option would be to add the path <HOME_DIR>/.local/share/wezterm/plugins/?.lua; and then have wezterm.plugin.ensure_installed(<url>) and wezterm.plugin.ensure_install_named(<url>, <name>) which would just ensure that the plugin is installed. Then the plugin author and user can then use require(<name>) as they like. Then the plugin authors is responsible to make a init.lua in the git root directory or have a readme which states which modules the plugin user should require. This feels like the most simple and elegant solution in my opinion.