Skip to content

Commit c861239

Browse files
committed
teamocil wip
1 parent f936cfa commit c861239

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

tmuxp/testsuite/test_config_teamocil.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,90 @@
1515
TMUXP_DIR = os.path.join(os.path.dirname(__file__), '.tmuxp')
1616

1717

18+
def teamocil_to_tmuxp(sconf):
19+
'''
20+
21+
:param sconf: python dict for session configuration
22+
:type sconf: dict
23+
'''
24+
25+
tmuxp_config = {}
26+
27+
if 'project_name' in sconf:
28+
tmuxp_config['session_name'] = sconf['project_name']
29+
elif 'name' in sconf:
30+
tmuxp_config['session_name'] = sconf['name']
31+
else:
32+
tmuxp_config['session_name'] = None
33+
34+
if 'cli_args' in sconf:
35+
tmuxp_config['config'] = sconf['cli_args']
36+
37+
if '-f' in tmuxp_config['config']:
38+
tmuxp_config['config'] = tmuxp_config['config'].replace('-f', '').strip()
39+
elif 'tmux_options' in sconf:
40+
tmuxp_config['config'] = sconf['tmux_options']
41+
42+
if '-f' in tmuxp_config['config']:
43+
tmuxp_config['config'] = tmuxp_config['config'].replace('-f', '').strip()
44+
45+
if 'socket_name' in sconf:
46+
tmuxp_config['socket_name'] = sconf['socket_name']
47+
48+
tmuxp_config['windows'] = []
49+
50+
if 'tabs' in sconf:
51+
sconf['windows'] = sconf.pop('tabs')
52+
53+
if 'pre' in sconf and 'pre_window' in sconf:
54+
tmuxp_config['shell_command'] = sconf['pre']
55+
56+
if isinstance(sconf['pre'], basestring):
57+
tmuxp_config['shell_command_before'] = [sconf['pre_window']]
58+
else:
59+
tmuxp_config['shell_command_before'] = sconf['pre_window']
60+
elif 'pre' in sconf:
61+
if isinstance(sconf['pre'], basestring):
62+
tmuxp_config['shell_command_before'] = [sconf['pre']]
63+
else:
64+
tmuxp_config['shell_command_before'] = sconf['pre']
65+
66+
if 'rbenv' in sconf:
67+
if 'shell_command_before' not in tmuxp_config:
68+
tmuxp_config['shell_command_before'] = []
69+
tmuxp_config['shell_command_before'].append(
70+
'rbenv shell %s' % sconf['rbenv']
71+
)
72+
73+
for w in sconf['windows']:
74+
for k, v in w.items():
75+
76+
windowdict = {}
77+
78+
windowdict['window_name'] = k
79+
80+
if isinstance(v, basestring) or v is None:
81+
windowdict['panes'] = [v]
82+
tmuxp_config['windows'].append(windowdict)
83+
continue
84+
elif isinstance(v, list):
85+
windowdict['panes'] = v
86+
tmuxp_config['windows'].append(windowdict)
87+
continue
88+
89+
if 'pre' in v:
90+
windowdict['shell_command_before'] = v['pre']
91+
if 'panes' in v:
92+
windowdict['panes'] = v['panes']
93+
94+
if 'layout' in v:
95+
windowdict['layout'] = v['layout']
96+
tmuxp_config['windows'].append(windowdict)
97+
98+
return tmuxp_config
99+
100+
101+
18102
class TeamocilTest(unittest.TestCase):
19103

20104
teamocil_yaml = """\
@@ -369,6 +453,9 @@ def test_config_to_dict(self):
369453
yaml_to_dict = test_config.get()
370454
self.assertDictEqual(yaml_to_dict, self.teamocil_dict)
371455

456+
''' this configuration contains multiple sessions in a single file.
457+
tmuxp can split them into files, proceed?
458+
'''
372459

373460
if __name__ == '__main__':
374461
unittest.main()

0 commit comments

Comments
 (0)