Skip to content

Commit e27425e

Browse files
committed
add import_teamocil, import_tmuxinator to config, add to docs.
1 parent ae15047 commit e27425e

File tree

4 files changed

+181
-164
lines changed

4 files changed

+181
-164
lines changed

doc/api.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ Command Line
8181

8282
.. automethod:: tmuxp.cli.startup
8383

84+
.. automethod:: tmuxp.cli.query_yes_no
85+
86+
.. automethod:: tmuxp.cli.setupLogger
87+
8488
Configuration
8589
-------------
8690

@@ -104,6 +108,10 @@ Import and export
104108

105109
.. automethod:: tmuxp.config.trickle
106110

111+
.. automethod:: tmuxp.config.import_teamocil
112+
113+
.. automethod:: tmuxp.config.import_tmuxinator
114+
107115
Workspace Builder
108116
-----------------
109117

tmuxp/config.py

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,152 @@ def trickle(config):
195195
paneconfig['shell_command'] = commands_before
196196

197197
return config
198+
199+
200+
def import_tmuxinator(sconf):
201+
'''
202+
:param sconf: python dict for session configuration
203+
:type sconf: dict
204+
205+
# https://github.com/aziz/tmuxinator
206+
# TODO: handle 'root' with a cd shell_command_before
207+
'''
208+
209+
tmuxp_config = {}
210+
211+
if 'project_name' in sconf:
212+
tmuxp_config['session_name'] = sconf['project_name']
213+
elif 'name' in sconf:
214+
tmuxp_config['session_name'] = sconf['name']
215+
else:
216+
tmuxp_config['session_name'] = None
217+
218+
if 'cli_args' in sconf:
219+
tmuxp_config['config'] = sconf['cli_args']
220+
221+
if '-f' in tmuxp_config['config']:
222+
tmuxp_config['config'] = tmuxp_config[
223+
'config'].replace('-f', '').strip()
224+
elif 'tmux_options' in sconf:
225+
tmuxp_config['config'] = sconf['tmux_options']
226+
227+
if '-f' in tmuxp_config['config']:
228+
tmuxp_config['config'] = tmuxp_config[
229+
'config'].replace('-f', '').strip()
230+
231+
if 'socket_name' in sconf:
232+
tmuxp_config['socket_name'] = sconf['socket_name']
233+
234+
tmuxp_config['windows'] = []
235+
236+
if 'tabs' in sconf:
237+
sconf['windows'] = sconf.pop('tabs')
238+
239+
if 'pre' in sconf and 'pre_window' in sconf:
240+
tmuxp_config['shell_command'] = sconf['pre']
241+
242+
if isinstance(sconf['pre'], basestring):
243+
tmuxp_config['shell_command_before'] = [sconf['pre_window']]
244+
else:
245+
tmuxp_config['shell_command_before'] = sconf['pre_window']
246+
elif 'pre' in sconf:
247+
if isinstance(sconf['pre'], basestring):
248+
tmuxp_config['shell_command_before'] = [sconf['pre']]
249+
else:
250+
tmuxp_config['shell_command_before'] = sconf['pre']
251+
252+
if 'rbenv' in sconf:
253+
if 'shell_command_before' not in tmuxp_config:
254+
tmuxp_config['shell_command_before'] = []
255+
tmuxp_config['shell_command_before'].append(
256+
'rbenv shell %s' % sconf['rbenv']
257+
)
258+
259+
for w in sconf['windows']:
260+
for k, v in w.items():
261+
262+
windowdict = {}
263+
264+
windowdict['window_name'] = k
265+
266+
if isinstance(v, basestring) or v is None:
267+
windowdict['panes'] = [v]
268+
tmuxp_config['windows'].append(windowdict)
269+
continue
270+
elif isinstance(v, list):
271+
windowdict['panes'] = v
272+
tmuxp_config['windows'].append(windowdict)
273+
continue
274+
275+
if 'pre' in v:
276+
windowdict['shell_command_before'] = v['pre']
277+
if 'panes' in v:
278+
windowdict['panes'] = v['panes']
279+
280+
if 'layout' in v:
281+
windowdict['layout'] = v['layout']
282+
tmuxp_config['windows'].append(windowdict)
283+
284+
return tmuxp_config
285+
286+
287+
def import_teamocil(sconf):
288+
'''
289+
:param sconf: python dict for session configuration
290+
:type sconf: dict
291+
292+
# https://github.com/remiprev/teamocil
293+
294+
# todo, change 'root' to a cd or start_directory
295+
# todo: width in pane -> main-pain-width
296+
# todo: with_env_var
297+
# todo: clear
298+
# todo: cmd_separator
299+
'''
300+
301+
tmuxp_config = {}
302+
303+
if 'session' in sconf:
304+
sconf = sconf['session']
305+
306+
if 'name' in sconf:
307+
tmuxp_config['session_name'] = sconf['name']
308+
else:
309+
tmuxp_config['session_name'] = None
310+
311+
tmuxp_config['windows'] = []
312+
313+
for w in sconf['windows']:
314+
315+
windowdict = {}
316+
317+
windowdict['window_name'] = w['name']
318+
if 'clear' in w:
319+
windowdict['clear'] = w['clear']
320+
321+
if 'filters' in w:
322+
if 'before' in w['filters']:
323+
for b in w['filters']['before']:
324+
windowdict['shell_command_before'] = w['filters']['before']
325+
if 'after' in w['filters']:
326+
for b in w['filters']['after']:
327+
windowdict['shell_command_after'] = w['filters']['after']
328+
329+
if 'splits' in w:
330+
w['panes'] = w.pop('splits')
331+
332+
if 'panes' in w:
333+
for p in w['panes']:
334+
if 'cmd' in p:
335+
p['shell_command'] = p.pop('cmd')
336+
if 'width' in p:
337+
# todo support for height/width
338+
p.pop('width')
339+
windowdict['panes'] = w['panes']
340+
341+
if 'layout' in w:
342+
windowdict['layout'] = w['layout']
343+
tmuxp_config['windows'].append(windowdict)
344+
345+
return tmuxp_config
346+

tmuxp/testsuite/test_config_teamocil.py

Lines changed: 16 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -14,67 +14,6 @@
1414
logger = logging.getLogger(__name__)
1515
TMUXP_DIR = os.path.join(os.path.dirname(__file__), '.tmuxp')
1616

17-
# todo, change 'root' to a cd or start_directory
18-
# todo: width in pane -> main-pain-width
19-
# todo: with_env_var
20-
# todo: clear
21-
# todo: cmd_separator
22-
23-
24-
def teamocil_to_tmuxp(sconf):
25-
'''
26-
27-
:param sconf: python dict for session configuration
28-
:type sconf: dict
29-
'''
30-
31-
tmuxp_config = {}
32-
33-
if 'session' in sconf:
34-
sconf = sconf['session']
35-
36-
if 'name' in sconf:
37-
tmuxp_config['session_name'] = sconf['name']
38-
else:
39-
tmuxp_config['session_name'] = None
40-
41-
tmuxp_config['windows'] = []
42-
43-
for w in sconf['windows']:
44-
45-
windowdict = {}
46-
47-
windowdict['window_name'] = w['name']
48-
if 'clear' in w:
49-
windowdict['clear'] = w['clear']
50-
51-
if 'filters' in w:
52-
if 'before' in w['filters']:
53-
for b in w['filters']['before']:
54-
windowdict['shell_command_before'] = w['filters']['before']
55-
if 'after' in w['filters']:
56-
for b in w['filters']['after']:
57-
windowdict['shell_command_after'] = w['filters']['after']
58-
59-
if 'splits' in w:
60-
w['panes'] = w.pop('splits')
61-
62-
if 'panes' in w:
63-
for p in w['panes']:
64-
if 'cmd' in p:
65-
p['shell_command'] = p.pop('cmd')
66-
if 'width' in p:
67-
# todo support for height/width
68-
p.pop('width')
69-
windowdict['panes'] = w['panes']
70-
71-
if 'layout' in w:
72-
windowdict['layout'] = w['layout']
73-
tmuxp_config['windows'].append(windowdict)
74-
75-
return tmuxp_config
76-
77-
7817
class TeamocilTest(unittest.TestCase):
7918

8019
teamocil_yaml = """\
@@ -134,12 +73,12 @@ def test_config_to_dict(self):
13473
self.assertDictEqual(yaml_to_dict, self.teamocil_dict)
13574

13675
self.assertDictEqual(
137-
teamocil_to_tmuxp(self.teamocil_dict),
76+
config.import_teamocil(self.teamocil_dict),
13877
self.tmuxp_dict
13978
)
14079

14180
config.check_consistency(
142-
teamocil_to_tmuxp(
81+
config.import_teamocil(
14382
self.teamocil_dict
14483
)
14584
)
@@ -211,12 +150,12 @@ def test_config_to_dict(self):
211150
self.assertDictEqual(yaml_to_dict, self.teamocil_dict)
212151

213152
self.assertDictEqual(
214-
teamocil_to_tmuxp(self.teamocil_dict),
153+
config.import_teamocil(self.teamocil_dict),
215154
self.tmuxp_dict
216155
)
217156

218157
config.check_consistency(
219-
teamocil_to_tmuxp(
158+
config.import_teamocil(
220159
self.teamocil_dict
221160
)
222161
)
@@ -298,12 +237,12 @@ def test_config_to_dict(self):
298237
self.assertDictEqual(yaml_to_dict, self.teamocil_dict)
299238

300239
self.assertDictEqual(
301-
teamocil_to_tmuxp(self.teamocil_dict),
240+
config.import_teamocil(self.teamocil_dict),
302241
self.tmuxp_dict
303242
)
304243

305244
config.check_consistency(
306-
teamocil_to_tmuxp(
245+
config.import_teamocil(
307246
self.teamocil_dict
308247
)
309248
)
@@ -351,12 +290,12 @@ def test_config_to_dict(self):
351290
self.assertDictEqual(yaml_to_dict, self.teamocil_dict)
352291

353292
self.assertDictEqual(
354-
teamocil_to_tmuxp(self.teamocil_dict),
293+
config.import_teamocil(self.teamocil_dict),
355294
self.tmuxp_dict
356295
)
357296

358297
config.check_consistency(
359-
teamocil_to_tmuxp(
298+
config.import_teamocil(
360299
self.teamocil_dict
361300
)
362301
)
@@ -724,52 +663,52 @@ def test_config_to_dict(self):
724663
self.assertDictEqual(yaml_to_dict, self.teamocil_dict)
725664

726665
self.assertDictEqual(
727-
teamocil_to_tmuxp(
666+
config.import_teamocil(
728667
self.teamocil_dict['two-windows'],
729668
),
730669
self.two_windows
731670
)
732671

733672
config.check_consistency(
734-
teamocil_to_tmuxp(
673+
config.import_teamocil(
735674
self.teamocil_dict['two-windows']
736675
)
737676
)
738677

739678
self.assertDictEqual(
740-
teamocil_to_tmuxp(
679+
config.import_teamocil(
741680
self.teamocil_dict['two-windows-with-filters'],
742681
),
743682
self.two_windows_with_filters
744683
)
745684

746685
config.check_consistency(
747-
teamocil_to_tmuxp(
686+
config.import_teamocil(
748687
self.teamocil_dict['two-windows-with-filters']
749688
)
750689
)
751690

752691
self.assertDictEqual(
753-
teamocil_to_tmuxp(
692+
config.import_teamocil(
754693
self.teamocil_dict['two-windows-with-custom-command-options'],
755694
),
756695
self.two_windows_with_custom_command_options
757696
)
758697

759698
config.check_consistency(
760-
teamocil_to_tmuxp(
699+
config.import_teamocil(
761700
self.teamocil_dict['two-windows-with-custom-command-options']
762701
)
763702
)
764703

765704
self.assertDictEqual(
766-
teamocil_to_tmuxp(
705+
config.import_teamocil(
767706
self.teamocil_dict['three-windows-within-a-session'],
768707
),
769708
self.three_windows_within_a_session
770709
)
771710
config.check_consistency(
772-
teamocil_to_tmuxp(
711+
config.import_teamocil(
773712
self.teamocil_dict['three-windows-within-a-session']
774713
)
775714
)

0 commit comments

Comments
 (0)