Skip to content

Commit 091cb56

Browse files
authored
feat: Command options / command structure (#752)
Fixes #751, in re: #53 #750
2 parents 46e8bc0 + 8dd1954 commit 091cb56

18 files changed

+192
-120
lines changed

CHANGES

+25
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,31 @@
6767

6868
- Fix loading of `.yml` files with `tmuxp convert`, thank you @kalixi! (#725)
6969

70+
#### Internal API
71+
72+
- #752: Command structure (internal API)
73+
74+
To pave the way for per-command options such as `enter: false` (#52), commands are now a different format:
75+
76+
Before, [`str`](str):
77+
78+
```python
79+
"echo hello"
80+
```
81+
82+
After, [`dict`](dict):
83+
84+
```python
85+
{
86+
"cmd": "echo hello"
87+
}
88+
```
89+
90+
This is purely internal. Normal usage should be the same since the
91+
configuration emits the equivalent result.
92+
93+
- #752: Configuration parsing refactorings
94+
7095
#### Development
7196

7297
- Run through black + isort with string normalization (#738). This way we can

tests/fixtures/config/expand1.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -36,39 +36,42 @@
3636
{
3737
"window_name": "editor",
3838
"panes": [
39-
{"shell_command": ["vim", "top"]},
40-
{"shell_command": ["vim"]},
41-
{"shell_command": ['cowsay "hey"']},
39+
{"shell_command": [{"cmd": "vim"}, {"cmd": "top"}]},
40+
{"shell_command": [{"cmd": "vim"}]},
41+
{"shell_command": [{"cmd": 'cowsay "hey"'}]},
4242
],
4343
"layout": "main-verticle",
4444
},
4545
{
4646
"window_name": "logging",
47-
"panes": [{"shell_command": ["tail -F /var/log/syslog"]}],
47+
"panes": [{"shell_command": [{"cmd": "tail -F /var/log/syslog"}]}],
4848
},
4949
{
5050
"start_directory": "/var/log",
5151
"options": {"automatic-rename": True},
52-
"panes": [{"shell_command": ["htop"]}, {"shell_command": ["vim"]}],
52+
"panes": [
53+
{"shell_command": [{"cmd": "htop"}]},
54+
{"shell_command": [{"cmd": "vim"}]},
55+
],
5356
},
5457
{
5558
"start_directory": os.path.normpath(
5659
os.path.join(os.path.expanduser("~"), "./")
5760
),
58-
"panes": [{"shell_command": ["pwd"]}],
61+
"panes": [{"shell_command": [{"cmd": "pwd"}]}],
5962
},
6063
{
6164
"start_directory": os.path.normpath(
6265
os.path.join(os.path.expanduser("~"), "./asdf")
6366
),
64-
"panes": [{"shell_command": ["pwd"]}],
67+
"panes": [{"shell_command": [{"cmd": "pwd"}]}],
6568
},
6669
{
6770
"start_directory": os.path.normpath(
6871
os.path.join(os.path.expanduser("~"), "../")
6972
),
70-
"panes": [{"shell_command": ["pwd"]}],
73+
"panes": [{"shell_command": [{"cmd": "pwd"}]}],
7174
},
72-
{"panes": [{"shell_command": ["top"]}]},
75+
{"panes": [{"shell_command": [{"cmd": "top"}]}]},
7376
],
7477
}

tests/fixtures/config/expand2-expanded.yaml

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,27 @@ windows:
66
focus: true
77
panes:
88
- shell_command:
9-
- cd ~
9+
- cmd: cd ~
1010
- shell_command:
11-
- cd /usr
11+
- cmd: cd /usr
1212
focus: true
1313
- shell_command:
14-
- cd ~
15-
- echo "moo"
16-
- top
14+
- cmd: cd ~
15+
- cmd: echo "moo"
16+
- cmd: top
1717
- window_name: window 2
1818
panes:
1919
- shell_command:
20-
- top
20+
- cmd: top
2121
focus: true
2222
- shell_command:
23-
- echo "hey"
23+
- cmd: echo "hey"
2424
- shell_command:
25-
- echo "moo"
25+
- cmd: echo "moo"
2626
- window_name: window 3
2727
panes:
2828
- shell_command:
29-
- cd /
29+
- cmd: cd /
3030
focus: true
3131
- shell_command: []
3232
- shell_command: []

tests/fixtures/config/expand_blank.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
{
2121
"window_name": "Empty string (return)",
2222
"panes": [
23-
{"shell_command": [""]},
24-
{"shell_command": [""]},
25-
{"shell_command": [""]},
23+
{"shell_command": [{"cmd": ""}]},
24+
{"shell_command": [{"cmd": ""}]},
25+
{"shell_command": [{"cmd": ""}]},
2626
],
2727
},
2828
{

tests/fixtures/config/shell_command_before.py

+52-23
Original file line numberDiff line numberDiff line change
@@ -43,35 +43,46 @@
4343
{
4444
"window_name": "editor",
4545
"start_directory": os.path.expanduser("~"),
46-
"shell_command_before": ["source .venv/bin/activate"],
46+
"shell_command_before": {
47+
"shell_command": [{"cmd": "source .venv/bin/activate"}]
48+
},
4749
"panes": [
48-
{"shell_command": ["vim"]},
50+
{"shell_command": [{"cmd": "vim"}]},
4951
{
50-
"shell_command_before": ["rbenv local 2.0.0-p0"],
51-
"shell_command": ['cowsay "hey"'],
52+
"shell_command_before": {
53+
"shell_command": [{"cmd": "rbenv local 2.0.0-p0"}]
54+
},
55+
"shell_command": [{"cmd": 'cowsay "hey"'}],
5256
},
5357
],
5458
"layout": "main-verticle",
5559
},
5660
{
57-
"shell_command_before": ["rbenv local 2.0.0-p0"],
61+
"shell_command_before": {
62+
"shell_command": [{"cmd": "rbenv local 2.0.0-p0"}]
63+
},
5864
"window_name": "logging",
5965
"panes": [
60-
{"shell_command": ["tail -F /var/log/syslog"]},
66+
{"shell_command": [{"cmd": "tail -F /var/log/syslog"}]},
6167
{"shell_command": []},
6268
],
6369
},
6470
{
6571
"window_name": "shufu",
6672
"panes": [
6773
{
68-
"shell_command_before": ["rbenv local 2.0.0-p0"],
69-
"shell_command": ["htop"],
74+
"shell_command_before": {
75+
"shell_command": [{"cmd": "rbenv local 2.0.0-p0"}]
76+
},
77+
"shell_command": [{"cmd": "htop"}],
7078
}
7179
],
7280
},
73-
{"options": {"automatic-rename": True}, "panes": [{"shell_command": ["htop"]}]},
74-
{"panes": [{"shell_command": ["top"]}]},
81+
{
82+
"options": {"automatic-rename": True},
83+
"panes": [{"shell_command": [{"cmd": "htop"}]}],
84+
},
85+
{"panes": [{"shell_command": [{"cmd": "top"}]}]},
7586
],
7687
}
7788

@@ -82,44 +93,62 @@
8293
{
8394
"window_name": "editor",
8495
"start_directory": os.path.expanduser("~"),
85-
"shell_command_before": ["source .venv/bin/activate"],
96+
"shell_command_before": {
97+
"shell_command": [{"cmd": "source .venv/bin/activate"}]
98+
},
8699
"panes": [
87-
{"shell_command": ["source .venv/bin/activate", "vim"]},
88100
{
89-
"shell_command_before": ["rbenv local 2.0.0-p0"],
90101
"shell_command": [
91-
"source .venv/bin/activate",
92-
"rbenv local 2.0.0-p0",
93-
'cowsay "hey"',
102+
{"cmd": "source .venv/bin/activate"},
103+
{"cmd": "vim"},
104+
]
105+
},
106+
{
107+
"shell_command_before": {
108+
"shell_command": [{"cmd": "rbenv local 2.0.0-p0"}]
109+
},
110+
"shell_command": [
111+
{"cmd": "source .venv/bin/activate"},
112+
{"cmd": "rbenv local 2.0.0-p0"},
113+
{"cmd": 'cowsay "hey"'},
94114
],
95115
},
96116
],
97117
"layout": "main-verticle",
98118
},
99119
{
100-
"shell_command_before": ["rbenv local 2.0.0-p0"],
120+
"shell_command_before": {
121+
"shell_command": [{"cmd": "rbenv local 2.0.0-p0"}]
122+
},
101123
"start_directory": "/",
102124
"window_name": "logging",
103125
"panes": [
104-
{"shell_command": ["rbenv local 2.0.0-p0", "tail -F /var/log/syslog"]},
105-
{"shell_command": ["rbenv local 2.0.0-p0"]},
126+
{
127+
"shell_command": [
128+
{"cmd": "rbenv local 2.0.0-p0"},
129+
{"cmd": "tail -F /var/log/syslog"},
130+
]
131+
},
132+
{"shell_command": [{"cmd": "rbenv local 2.0.0-p0"}]},
106133
],
107134
},
108135
{
109136
"start_directory": "/",
110137
"window_name": "shufu",
111138
"panes": [
112139
{
113-
"shell_command_before": ["rbenv local 2.0.0-p0"],
114-
"shell_command": ["rbenv local 2.0.0-p0", "htop"],
140+
"shell_command_before": {
141+
"shell_command": [{"cmd": "rbenv local 2.0.0-p0"}]
142+
},
143+
"shell_command": [{"cmd": "rbenv local 2.0.0-p0"}, {"cmd": "htop"}],
115144
}
116145
],
117146
},
118147
{
119148
"start_directory": "/",
120149
"options": {"automatic-rename": True},
121-
"panes": [{"shell_command": ["htop"]}],
150+
"panes": [{"shell_command": [{"cmd": "htop"}]}],
122151
},
123-
{"start_directory": "/", "panes": [{"shell_command": ["top"]}]},
152+
{"start_directory": "/", "panes": [{"shell_command": [{"cmd": "top"}]}]},
124153
],
125154
}
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
shell_command_before:
2-
- 'echo "hi"'
2+
shell_command:
3+
- cmd: 'echo "hi"'
34
session_name: 'test'
45
windows:
56
- window_name: editor
67
panes:
78
- shell_command:
8-
- 'echo "hi"'
9-
- vim
10-
- :Ex
9+
- cmd: 'echo "hi"'
10+
- cmd: vim
11+
- cmd: :Ex
1112
- shell_command:
12-
- 'echo "hi"'
13+
- cmd: 'echo "hi"'
1314
- shell_command:
14-
- 'echo "hi"'
15-
- cd /usr
15+
- cmd: 'echo "hi"'
16+
- cmd: cd /usr
1617
- window_name: logging
1718
panes:
1819
- shell_command:
19-
- 'echo "hi"'
20+
- cmd: 'echo "hi"'
2021
- shell_command:
21-
- 'echo "hi"'
22-
- top
23-
- emacs
22+
- cmd: 'echo "hi"'
23+
- cmd: top
24+
- cmd: emacs

tests/fixtures/config/trickle.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
{
66
"window_name": "editor",
77
"start_directory": "log",
8-
"panes": [{"shell_command": ["vim"]}, {"shell_command": ['cowsay "hey"']}],
8+
"panes": [
9+
{"shell_command": [{"cmd": "vim"}]},
10+
{"shell_command": [{"cmd": 'cowsay "hey"'}]},
11+
],
912
"layout": "main-verticle",
1013
},
1114
{
1215
"window_name": "logging",
1316
"start_directory": "~",
1417
"panes": [
15-
{"shell_command": ["tail -F /var/log/syslog"]},
18+
{"shell_command": [{"cmd": "tail -F /var/log/syslog"}]},
1619
{"shell_command": []},
1720
],
1821
},
@@ -26,14 +29,17 @@
2629
{
2730
"window_name": "editor",
2831
"start_directory": "/var/log",
29-
"panes": [{"shell_command": ["vim"]}, {"shell_command": ['cowsay "hey"']}],
32+
"panes": [
33+
{"shell_command": [{"cmd": "vim"}]},
34+
{"shell_command": [{"cmd": 'cowsay "hey"'}]},
35+
],
3036
"layout": "main-verticle",
3137
},
3238
{
3339
"start_directory": "~",
3440
"window_name": "logging",
3541
"panes": [
36-
{"shell_command": ["tail -F /var/log/syslog"]},
42+
{"shell_command": [{"cmd": "tail -F /var/log/syslog"}]},
3743
{"shell_command": []},
3844
],
3945
},

tests/fixtures/workspacebuilder/focus_and_pane.yaml

+10-9
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,27 @@ windows:
55
focus: true
66
panes:
77
- shell_command:
8-
- cd ~
8+
- cmd: cd ~
99
- shell_command:
10-
- cd /usr
10+
- cmd: cd /usr
1111
focus: true
1212
- shell_command:
13-
- cd ~
14-
- echo "moo"
15-
- top
13+
- cmd: cd ~
14+
- cmd: echo "moo"
15+
- cmd: top
1616
- window_name: window 2
1717
panes:
1818
- shell_command:
19-
- top
19+
- cmd: top
2020
focus: true
2121
- shell_command:
22-
- echo "hey"
22+
- cmd: echo "hey"
2323
- shell_command:
24-
- echo "moo"
24+
- cmd: echo "moo"
2525
- window_name: window 3
2626
panes:
27-
- shell_command: cd /
27+
- shell_command:
28+
- cmd: cd /
2829
focus: true
2930
- pane
3031
- pane

tests/fixtures/workspacebuilder/plugin_bs.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ windows:
55
- window_name: editor
66
layout: tiled
77
shell_command_before:
8-
- cd ~/
8+
- cmd: cd ~/
99
panes:
1010
- shell_command:
11-
- cd /var/log
12-
- ls -al | grep \.log
13-
- echo hello
14-
- echo hello
15-
- echo hello
11+
- cmd: cd /var/log
12+
- cmd: ls -al | grep \.log
13+
- cmd: echo hello
14+
- cmd: echo hello
15+
- cmd: echo hello

0 commit comments

Comments
 (0)