|
| 1 | +.. _plugin_system: |
| 2 | + |
| 3 | +============= |
| 4 | +Plugin System |
| 5 | +============= |
| 6 | + |
| 7 | +The plugin system allows users to customize and extend different aspects of |
| 8 | +tmuxp without the need to change tmuxp itself. |
| 9 | + |
| 10 | + |
| 11 | +Using a Plugin |
| 12 | +-------------- |
| 13 | + |
| 14 | +To use a plugin, install it in your local python environment and add it to |
| 15 | +your tmuxp configuration file. |
| 16 | + |
| 17 | +Example Configurations |
| 18 | +^^^^^^^^^^^^^^^^^^^^^^ |
| 19 | +YAML |
| 20 | +~~~~ |
| 21 | + |
| 22 | +.. literalinclude:: ../examples/plugin-system.yaml |
| 23 | + :language: yaml |
| 24 | + |
| 25 | +JSON |
| 26 | +~~~~ |
| 27 | + |
| 28 | +.. literalinclude:: ../examples/plugin-system.json |
| 29 | + :language: json |
| 30 | + |
| 31 | +.. _poetry: https://python-poetry.org/ |
| 32 | + |
| 33 | + |
| 34 | +Developing a Plugin |
| 35 | +------------------- |
| 36 | + |
| 37 | +.. module:: tmuxp |
| 38 | + |
| 39 | +Plugin API |
| 40 | +^^^^^^^^^^ |
| 41 | + |
| 42 | +.. automethod:: tmuxp.plugin.TmuxpPluginInterface.before_workspace_builder |
| 43 | +.. automethod:: tmuxp.plugin.TmuxpPluginInterface.on_window_create |
| 44 | +.. automethod:: tmuxp.plugin.TmuxpPluginInterface.after_window_finished |
| 45 | +.. automethod:: tmuxp.plugin.TmuxpPluginInterface.before_script |
| 46 | +.. automethod:: tmuxp.plugin.TmuxpPluginInterface.reattach |
| 47 | + |
| 48 | + |
| 49 | +Example Plugin |
| 50 | +-------------- |
| 51 | + |
| 52 | +Tmuxp expects all plugins to be class within a python submodule named |
| 53 | +``plugin`` that is within a python module that is installed in the local |
| 54 | +python environment. A plugin interface is provided by tmuxp to inherit. |
| 55 | + |
| 56 | +`poetry`_ is the chosen python package manager for tmuxp. It is highly |
| 57 | +suggested to use it when developing tmuxp plugins; however, ``pip`` will work |
| 58 | +just as well. |
| 59 | + |
| 60 | +.. code-block:: bash |
| 61 | +
|
| 62 | + python_module |
| 63 | + ├── my_plugin_module |
| 64 | + │ ├── __init__.py |
| 65 | + │ └── plugin.py |
| 66 | + ├── pyproject.toml # Poetry's module configuration file |
| 67 | + └── setup.py # pip's module configuration file |
| 68 | +
|
| 69 | +The `plugin.py` file could contain something like the following: |
| 70 | + |
| 71 | +.. code-block:: python |
| 72 | + |
| 73 | + from tmuxp.plugin import TmuxpPluginInterface |
| 74 | + import datetime |
| 75 | +
|
| 76 | + class MyTmuxpPlugin(TmuxpPluginInterface): |
| 77 | + def __init__(self): |
| 78 | + super.__init__(self) |
| 79 | +
|
| 80 | + def before_workspace_builder(self, session): |
| 81 | + session.rename_session('my-new-session-name') |
| 82 | +
|
| 83 | + def reattach(self, session): |
| 84 | + now = datetime.datetime.now().strftime('%Y-%m-%d') |
| 85 | + session.rename_session('session_{}'.format(now)) |
| 86 | +
|
| 87 | +Once this plugin is installed in the local python environment, it can be used |
| 88 | +in a configuration file like the following: |
| 89 | + |
| 90 | +.. code-block: yaml |
| 91 | +
|
| 92 | + session_name: plugin example |
| 93 | + plugins: |
| 94 | + - my_plugin_module.plugin.MyTmuxpPlugin |
| 95 | + # ... the rest of your config |
0 commit comments