Skip to content

Commit 4f10ebd

Browse files
committed
Relative start_directory paths. When loading, start_directory is relative to the config file
1 parent ccc675d commit 4f10ebd

File tree

4 files changed

+72
-30
lines changed

4 files changed

+72
-30
lines changed

examples/start_directory.json

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,70 @@
22
"windows": [
33
{
44
"panes": [
5-
"pwd",
6-
"echo 'it trickles down from session-level'"
5+
{
6+
"shell_command": [
7+
"echo \"\\033c",
8+
"it trickles down from session-level\""
9+
]
10+
},
11+
"pwd"
712
],
813
"window_name": "should be /var/"
914
},
1015
{
1116
"panes": [
12-
"pwd",
13-
"echo 'window start_directory concatenates to session start_directory'",
14-
"echo 'if it is not absolute'"
17+
{
18+
"shell_command": [
19+
"echo '\\033c",
20+
"window start_directory concatenates to session start_directory",
21+
"if it is not absolute'"
22+
]
23+
},
24+
"pwd"
1525
],
1626
"start_directory": "log",
1727
"window_name": "should be /var/log"
1828
},
1929
{
2030
"panes": [
21-
"pwd",
22-
"echo 'has precedence'",
23-
"echo 'remember to quote ~ in YAML'"
31+
{
32+
"shell_command": [
33+
"echo \\\\033c ~ has precedence. note: remember to quote ~ in YAML"
34+
]
35+
},
36+
"pwd"
2437
],
2538
"start_directory": "~",
2639
"window_name": "should be ~"
2740
},
2841
{
2942
"panes": [
30-
"pwd",
31-
"echo 'absolute paths also have precedence'"
43+
"echo '\\033c absolute paths also have precedence.'",
44+
"pwd"
3245
],
3346
"start_directory": "/proc",
3447
"window_name": "should be /proc"
48+
},
49+
{
50+
"panes": [
51+
{
52+
"shell_command": [
53+
"echo '\\033c",
54+
"./ is relative to config file location",
55+
"../ will be parent of config file",
56+
"./test will be \\\"test\\\" dir inside dir of config file'"
57+
]
58+
},
59+
{
60+
"shell_command": [
61+
"echo '\\033c",
62+
"This way you can load up workspaces from projects and maintain",
63+
"relative paths.'"
64+
]
65+
}
66+
],
67+
"start_directory": "./",
68+
"window_name": "should be config's dir"
3569
}
3670
],
3771
"session_name": "start directory",

examples/start_directory.yaml

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,38 @@ start_directory: /var/
33
windows:
44
- window_name: should be /var/
55
panes:
6-
- pwd
7-
- echo 'it trickles down from session-level'
6+
- shell_command:
7+
- echo "\033c
8+
- it trickles down from session-level"
9+
- pwd
810
- window_name: should be /var/log
911
start_directory: log
1012
panes:
13+
- shell_command:
14+
- echo '\033c
15+
- window start_directory concatenates to session start_directory
16+
- if it is not absolute'
1117
- pwd
12-
- echo 'window start_directory concatenates to session start_directory'
13-
- echo 'if it is not absolute'
1418
- window_name: should be ~
1519
start_directory: '~'
1620
panes:
21+
- shell_command:
22+
- 'echo \\033c ~ has precedence. note: remember to quote ~ in YAML'
1723
- pwd
18-
- echo 'has precedence'
19-
- echo 'remember to quote ~ in YAML'
2024
- window_name: should be /proc
2125
start_directory: /proc
2226
panes:
27+
- echo '\033c absolute paths also have precedence.'
2328
- pwd
24-
- echo 'absolute paths also have precedence'
29+
- window_name: should be config's dir
30+
start_directory: ./
31+
panes:
32+
- shell_command:
33+
- echo '\033c
34+
- ./ is relative to config file location
35+
- ../ will be parent of config file
36+
- ./test will be \"test\" dir inside dir of config file'
37+
- shell_command:
38+
- echo '\033c
39+
- This way you can load up workspaces from projects and maintain
40+
- relative paths.'

tmuxp/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def load_workspace(config_file, args):
226226

227227
sconfig = kaptan.Kaptan()
228228
sconfig = sconfig.import_config(config_file).get()
229-
sconfig = config.expand(sconfig)
229+
sconfig = config.expand(sconfig, os.path.dirname(config_file))
230230
sconfig = config.trickle(sconfig)
231231

232232
t = Server(

tmuxp/testsuite/test_config.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,12 @@ def test_config(self):
257257
"""Expand shell commands from string to list."""
258258
self.maxDiff = None
259259
test_config = config.expand(self.before_config)
260-
logger.error(test_config)
261260
self.assertDictEqual(test_config, self.after_config)
262261

263262

264263
class InlineTest(unittest.TestCase):
265264

266-
'''tests for :meth:`config.inline()`.
267-
'''
265+
"""Tests for :meth:`config.inline()`."""
268266

269267
before_config = {
270268
'session_name': 'sampleconfig',
@@ -339,21 +337,15 @@ class InlineTest(unittest.TestCase):
339337
}
340338

341339
def test_config(self):
342-
'''
343-
config.inline() inlines shell commands from list to string where applicable
344-
'''
340+
""":meth:`config.inline()` shell commands list to string where applicable."""
341+
345342
self.maxDiff = None
346343
test_config = config.inline(self.before_config)
347344
self.assertDictEqual(test_config, self.after_config)
348345

349346

350347
class InheritanceTest(unittest.TestCase):
351-
352-
'''
353-
test config inheritance for the nested 'start_command'
354-
355-
format for tests will be
356-
'''
348+
"""Test config inheritance for the nested 'start_command'."""
357349

358350
config_before = {
359351
'session_name': 'sampleconfig',

0 commit comments

Comments
 (0)