Skip to content

Commit 5d66126

Browse files
committed
Fix config.trickle to pass down start_directory properly. Assure that StartDirectory works correctly.
1 parent 6c07006 commit 5d66126

File tree

3 files changed

+39
-19
lines changed

3 files changed

+39
-19
lines changed

tmuxp/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,11 @@ def trickle(config):
190190
``shell_command_before``.
191191
'''
192192

193+
session_start_directory = config['start_directory'] if 'start_directory' in config else None
194+
193195
for windowconfig in config['windows']:
196+
if not 'start_directory' in windowconfig and session_start_directory:
197+
windowconfig['start_directory'] = session_start_directory
194198
for paneconfig in windowconfig['panes']:
195199
commands_before = config[
196200
'shell_command_before'] if 'shell_command_before' in config else []

tmuxp/testsuite/test_config.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ class ExpandTest(unittest.TestCase):
144144
'window_name': 'editor',
145145
'panes': [
146146
{
147-
'start_directory': '~', 'shell_command': ['vim'],
148-
}, {
147+
'shell_command': ['vim'],
148+
},
149+
{
149150
'shell_command': 'cowsay "hey"'
150151
},
151152
],
@@ -154,7 +155,7 @@ class ExpandTest(unittest.TestCase):
154155
'window_name': 'logging',
155156
'panes': [
156157
{'shell_command': ['tail -F /var/log/syslog'],
157-
'start_directory':'/var/log'}
158+
}
158159
]
159160
},
160161
{
@@ -181,7 +182,7 @@ class ExpandTest(unittest.TestCase):
181182
'window_name': 'editor',
182183
'panes': [
183184
{
184-
'start_directory': '~', 'shell_command': ['vim'],
185+
'shell_command': ['vim'],
185186
}, {
186187
'shell_command': ['cowsay "hey"']
187188
},
@@ -192,7 +193,7 @@ class ExpandTest(unittest.TestCase):
192193
'window_name': 'logging',
193194
'panes': [
194195
{'shell_command': ['tail -F /var/log/syslog'],
195-
'start_directory':'/var/log'}
196+
}
196197
]
197198
},
198199
{
@@ -215,6 +216,7 @@ def test_config(self):
215216
'''
216217
expands shell commands from string to list
217218
'''
219+
self.maxDiff = None
218220
test_config = config.expand(self.before_config)
219221
self.assertDictEqual(test_config, self.after_config)
220222

@@ -426,7 +428,7 @@ class ShellCommandBeforeTest(unittest.TestCase):
426428
'shell_command_before': 'source .env/bin/activate',
427429
'panes': [
428430
{
429-
'start_directory': '~', 'shell_command': ['vim'],
431+
'shell_command': ['vim'],
430432
}, {
431433
'shell_command_before': ['rbenv local 2.0.0-p0'], 'shell_command': ['cowsay "hey"']
432434
},
@@ -438,17 +440,17 @@ class ShellCommandBeforeTest(unittest.TestCase):
438440
'window_name': 'logging',
439441
'panes': [
440442
{'shell_command': ['tail -F /var/log/syslog'],
441-
'start_directory':'/var/log'},
443+
},
442444
{
443-
'start_directory': '/var/log'}
445+
}
444446
]
445447
},
446448
{
447449
'window_name': 'shufu',
448450
'panes': [
449451
{
450452
'shell_command_before': ['rbenv local 2.0.0-p0'],
451-
'shell_command': ['htop'], 'start_directory': '/etc/'}
453+
'shell_command': ['htop'], }
452454
]
453455
},
454456
{
@@ -473,7 +475,7 @@ class ShellCommandBeforeTest(unittest.TestCase):
473475
'shell_command_before': ['source .env/bin/activate'],
474476
'panes': [
475477
{
476-
'start_directory': '~', 'shell_command': ['vim'],
478+
'shell_command': ['vim'],
477479
}, {
478480
'shell_command_before': ['rbenv local 2.0.0-p0'], 'shell_command': ['cowsay "hey"']
479481
},
@@ -485,17 +487,17 @@ class ShellCommandBeforeTest(unittest.TestCase):
485487
'window_name': 'logging',
486488
'panes': [
487489
{'shell_command': ['tail -F /var/log/syslog'],
488-
'start_directory':'/var/log'},
490+
},
489491
{
490-
'start_directory': '/var/log'}
492+
}
491493
]
492494
},
493495
{
494496
'window_name': 'shufu',
495497
'panes': [
496498
{
497499
'shell_command_before': ['rbenv local 2.0.0-p0'],
498-
'shell_command': ['htop'], 'start_directory': '/etc/'}
500+
'shell_command': ['htop'],}
499501
]
500502
},
501503
{
@@ -522,7 +524,6 @@ class ShellCommandBeforeTest(unittest.TestCase):
522524
'shell_command_before': ['source .env/bin/activate'],
523525
'panes': [
524526
{
525-
'start_directory': '~',
526527
'shell_command': ['source .env/bin/activate', 'vim'],
527528
}, {
528529
'shell_command_before': ['rbenv local 2.0.0-p0'],
@@ -536,29 +537,33 @@ class ShellCommandBeforeTest(unittest.TestCase):
536537
},
537538
{
538539
'shell_command_before': ['rbenv local 2.0.0-p0'],
540+
'start_directory': '/',
539541
'window_name': 'logging',
540542
'panes': [
541543
{'shell_command': ['rbenv local 2.0.0-p0', 'tail -F /var/log/syslog'],
542-
'start_directory':'/var/log'},
544+
},
543545
{
544-
'start_directory': '/var/log', 'shell_command': ['rbenv local 2.0.0-p0']}
546+
'shell_command': ['rbenv local 2.0.0-p0']}
545547
]
546548
},
547549
{
550+
'start_directory': '/',
548551
'window_name': 'shufu',
549552
'panes': [
550553
{
551554
'shell_command_before': ['rbenv local 2.0.0-p0'],
552-
'shell_command': ['rbenv local 2.0.0-p0', 'htop'], 'start_directory': '/etc/'}
555+
'shell_command': ['rbenv local 2.0.0-p0', 'htop'],}
553556
]
554557
},
555558
{
559+
'start_directory': '/',
556560
'options': {'automatic_rename': True, },
557561
'panes': [
558562
{'shell_command': ['htop']}
559563
]
560564
},
561565
{
566+
'start_directory': '/',
562567
'panes': [
563568
{'shell_command': ['top']}
564569
]

tmuxp/testsuite/test_workspacebuilder.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def test_automatic_rename_option(self):
271271
class StartDirectoryTest(TmuxTestCase):
272272
yaml_config = '''
273273
session_name: sampleconfig
274-
#start_directory: '/home/tony'
274+
start_directory: '/var'
275275
windows:
276276
- window_name: test
277277
start_directory: '/var/log'
@@ -293,20 +293,31 @@ class StartDirectoryTest(TmuxTestCase):
293293
- echo "hey"
294294
- shell_command:
295295
- echo "moo"
296+
- window_name: testsa3
297+
layout: main-horizontal
298+
panes:
299+
- shell_command:
300+
- pwd
301+
- shell_command:
302+
- echo "hey"
303+
- shell_command:
304+
- echo "moo3"
296305
'''
297306

298307
def test_start_directory(self):
299308

300309
sconfig = kaptan.Kaptan(handler='yaml')
301310
sconfig = sconfig.import_config(self.yaml_config).get()
311+
sconfig = config.expand(sconfig)
312+
sconfig = config.trickle(sconfig)
302313

303314
builder = WorkspaceBuilder(sconf=sconfig)
304315
builder.build(session=self.session)
305316

306317
assert(self.session == builder.session)
307318
for window in self.session.windows:
308319
for p in window.panes:
309-
self.assertTrue(any(p.get('pane_start_path', ['/var/log', '/dev/'])))
320+
self.assertTrue(any(p.get('pane_start_path', ['/var/log', '/dev/', '/var/'])))
310321

311322
if __name__ == '__main__':
312323
unittest.main()

0 commit comments

Comments
 (0)