77"""
88from __future__ import absolute_import
99
10+ import importlib
1011import logging
1112import os
1213import sys
@@ -192,6 +193,35 @@ def set_layout_hook(session, hook_name):
192193 session .cmd (* cmd )
193194
194195
196+ def load_plugins (sconfig ):
197+ plugins = []
198+ if 'plugins' in sconfig :
199+ for plugin in sconfig ['plugins' ]:
200+ try :
201+ """
202+ click.echo(
203+ click.style('[Loading] ', fg='green')
204+ + click.style(f'Plugin: {plugin}', fg='blue', bold=True)
205+ )
206+ """
207+ module_name = plugin .split ('.' )
208+ module_name = '.' .join (module_name [:- 1 ])
209+ plugin_name = plugin .split ('.' )[- 1 ]
210+ plugin = getattr (importlib .import_module (module_name ), plugin_name )
211+ plugins .append (plugin ())
212+ except Exception as error :
213+ click .echo (
214+ click .wrap_text (
215+ f'Error in loading { plugin } . Please make '
216+ f'sure { plugin } is installed.\n \n '
217+ f'{ error } '
218+ )
219+ )
220+
221+ return plugins
222+
223+
224+
195225def is_pure_name (path ):
196226 """
197227 Return True if path is a name and not a file path.
@@ -276,7 +306,7 @@ def scan_config(config, config_dir=None):
276306
277307 If config is directory, scan for .tmuxp.{yaml,yml,json} in directory. If
278308 one or more found, it will warn and pick the first.
279-
309+ [Loading]
280310 If config is ".", "./" or None, it will scan current directory.
281311
282312 If config is has no path and only a filename, e.g. "myconfig.yaml" it will
@@ -372,7 +402,7 @@ def scan_config(config, config_dir=None):
372402 return config
373403
374404
375- def _reattach (session ):
405+ def _reattach (session , plugins ):
376406 """
377407 Reattach session (depending on env being inside tmux already or not)
378408
@@ -388,6 +418,10 @@ def _reattach(session):
388418
389419 If not, ``tmux attach-session`` loads the client to the target session.
390420 """
421+
422+ for plugin in plugins :
423+ plugin .reattach (session )
424+
391425 if 'TMUX' in os .environ :
392426 session .switch_client ()
393427
@@ -513,8 +547,10 @@ def load_workspace(
513547
514548 which ('tmux' ) # raise exception if tmux not found
515549
550+ plugins = load_plugins (sconfig )
551+
516552 try : # load WorkspaceBuilder object for tmuxp config / tmux server
517- builder = WorkspaceBuilder (sconf = sconfig , server = t )
553+ builder = WorkspaceBuilder (sconf = sconfig , server = t , plugins = plugins )
518554 except exc .EmptyConfigException :
519555 click .echo ('%s is empty or parsed no config data' % config_file , err = True )
520556 return
@@ -532,7 +568,7 @@ def load_workspace(
532568 default = True ,
533569 )
534570 ):
535- _reattach (builder .session )
571+ _reattach (builder .session , plugins )
536572 return
537573
538574 try :
0 commit comments