Skip to content

Commit c13bda3

Browse files
committed
Doc updates, convert YAML to/from JSON. Examples for JSON and YAML
1 parent 3f890d4 commit c13bda3

File tree

9 files changed

+271
-16
lines changed

9 files changed

+271
-16
lines changed

.tmuxp.json

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"windows": [
3+
{
4+
"panes": [
5+
{
6+
"shell_command": [
7+
"vim",
8+
":Ex"
9+
],
10+
"focus": true
11+
},
12+
{
13+
"shell_command": [
14+
"echo hi"
15+
]
16+
},
17+
{
18+
"shell_command": [
19+
"command -v .env/bin/tmuxp >/dev/null 2>&1 || { pip install -e .; }",
20+
"command -v watching_testrunner >/dev/null 2>&1 || { pip install watching_testrunner; }",
21+
"watching_testrunner --basepath ./ --pattern=\"*.py\" 'python run_tests.py'"
22+
]
23+
}
24+
],
25+
"shell_command_before": [
26+
"command -v virtualenv >/dev/null 2>&1 || { pip install virtualenv; }",
27+
"[ -d .env -a -f .env/bin/activate ] && source .env/bin/activate || virtualenv .env",
28+
"[ ! -d .env/build ] || rm -rf .env/build"
29+
],
30+
"layout": "main-horizontal",
31+
"window_name": "tmuxp",
32+
"options": {
33+
"main-pane-height": 50
34+
}
35+
},
36+
{
37+
"panes": [
38+
{
39+
"shell_command": [
40+
"vim"
41+
],
42+
"focus": true
43+
},
44+
"pwd",
45+
"echo 'docs built to <http://0.0.0.0:8000/_build/html>'; python -m SimpleHTTPServer",
46+
{
47+
"shell_command": [
48+
"command -v sphinx-quickstart >/dev/null 2>&1 || { pip install -r requirements.pip; }",
49+
"command -v watching_testrunner >/dev/null 2>&1 || { pip install watching_testrunner; }",
50+
"watching_testrunner --basepath ./ --pattern=\"*.rst\" 'make html'",
51+
"python -m SimpleHTTPServer"
52+
]
53+
}
54+
],
55+
"shell_command_before": [
56+
"command -v virtualenv >/dev/null 2>&1 || { pip install virtualenv; }",
57+
"[ -d .env -a -f .env/bin/activate ] && source .env/bin/activate || virtualenv .env",
58+
"[ ! -d .env/build ] || rm -rf .env/build",
59+
"command -v .env/bin/tmuxp >/dev/null 2>&1 || { pip install -e .; }",
60+
"cd ./doc"
61+
],
62+
"layout": "main-horizontal",
63+
"window_name": "docs",
64+
"options": {
65+
"main-pane-height": 50
66+
}
67+
}
68+
],
69+
"session_name": "tmuxp"
70+
}

README.rst

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ Load a session configuration from a YAML or JSON file.
4646

4747
.. code-block:: bash
4848
49-
$ tmuxp load<tab>
49+
$ tmuxp load<tab> # configs in config dir, current directory
50+
51+
Convert a session config JSON <=> YAML:
52+
53+
.. code-block:: bash
54+
55+
$ tmuxp convert<tab> # configs in config dir, current directory
5056
5157
See: `bash completion`_
5258

@@ -69,13 +75,29 @@ Load ``myconfig.yaml``.
6975

7076
.. code-block:: yaml
7177
72-
session_name: my session
78+
session_name: 2-pane-vertical
7379
windows:
74-
- window_name: my test window
75-
shell_command_before: cd ~
76-
panes:
77-
- pwd
78-
- pwd
80+
- window_name: my test window
81+
panes:
82+
- pwd
83+
- pwd
84+
85+
or ``~/.tmuxp/test.json``:
86+
87+
.. code-block:: json
88+
89+
{
90+
"windows": [
91+
{
92+
"panes": [
93+
"pwd",
94+
"pwd"
95+
],
96+
"window_name": "my test window"
97+
}
98+
],
99+
"session_name": "2-pane-vertical"
100+
}
79101
80102
.. code-block:: bash
81103

doc/examples.rst

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,30 @@ Examples
2121
| |
2222
+-----------------+
2323

24-
YAML - Short form:
24+
YAML - Short form
25+
"""""""""""""""""
2526

2627
.. literalinclude:: ../examples/2-pane-vertical.yaml
2728
:language: yaml
2829

29-
YAML - Christmas Tree:
30+
JSON - Short form
31+
"""""""""""""""""
32+
33+
.. literalinclude:: ../examples/2-pane-vertical.json
34+
:language: json
35+
36+
YAML - Christmas Tree
37+
"""""""""""""""""""""
3038

3139
.. literalinclude:: ../examples/2-pane-vertical-long.yaml
3240
:language: yaml
3341

42+
JSON - Christmas Tree
43+
"""""""""""""""""""""
44+
45+
.. literalinclude:: ../examples/2-pane-vertical-long.json
46+
:language: json
47+
3448
3 panes
3549
-------
3650

@@ -48,9 +62,18 @@ YAML - Christmas Tree:
4862
| | |
4963
+--------+--------+
5064

65+
YAML
66+
""""
67+
5168
.. literalinclude:: ../examples/3-pane.yaml
5269
:language: yaml
5370

71+
JSON
72+
""""
73+
74+
.. literalinclude:: ../examples/3-pane.json
75+
:language: json
76+
5477
4 panes
5578
-------
5679

@@ -68,18 +91,38 @@ YAML - Christmas Tree:
6891
| | |
6992
+--------+--------+
7093

94+
YAML
95+
""""
96+
7197
.. literalinclude:: ../examples/4-pane.yaml
7298
:language: yaml
7399

100+
JSON
101+
""""
102+
103+
.. literalinclude:: ../examples/4-pane.json
104+
:language: json
105+
106+
74107
Super-advanced dev environment
75108
------------------------------
76109

77110
.. seealso::
78111
:ref:`tmuxp developer config` in the :ref:`developing` section.
79112

113+
YAML
114+
""""
115+
80116
.. literalinclude:: ../.tmuxp.yaml
81117
:language: yaml
82118

119+
JSON
120+
""""
121+
122+
.. literalinclude:: ../.tmuxp.json
123+
:language: json
124+
125+
83126
Kung fu
84127
-------
85128

doc/index.rst

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,29 @@ To install ``tmuxp``:
4545

4646
.. code-block:: yaml
4747
48-
session_name: my session
48+
session_name: 2-pane-vertical
4949
windows:
50-
- window_name: my test window
51-
panes:
52-
- pwd
53-
- pwd
54-
55-
Now with ``tmuxp``:
50+
- window_name: my test window
51+
panes:
52+
- pwd
53+
- pwd
54+
55+
or ``~/.tmuxp/test.json``:
56+
57+
.. code-block:: json
58+
59+
{
60+
"windows": [
61+
{
62+
"panes": [
63+
"pwd",
64+
"pwd"
65+
],
66+
"window_name": "my test window"
67+
}
68+
],
69+
"session_name": "2-pane-vertical"
70+
}
5671
5772
.. code-block:: bash
5873

examples/2-pane-vertical-long.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"windows": [
3+
{
4+
"panes": [
5+
{
6+
"shell_command": [
7+
"cd ~",
8+
"pwd",
9+
"top"
10+
]
11+
},
12+
{
13+
"shell_command": [
14+
"cd /var/www",
15+
"pwd"
16+
]
17+
}
18+
],
19+
"window_name": "test"
20+
},
21+
{
22+
"panes": [
23+
{
24+
"shell_command": "pwd"
25+
},
26+
{
27+
"shell_command": [
28+
"pwd"
29+
]
30+
}
31+
],
32+
"shell_command_before": "cd /var/www",
33+
"window_name": "second window"
34+
}
35+
],
36+
"session_name": "2-pane-vertical-long"
37+
}

examples/2-pane-vertical.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"windows": [
3+
{
4+
"panes": [
5+
"pwd",
6+
"pwd"
7+
],
8+
"window_name": "my test window"
9+
}
10+
],
11+
"session_name": "2-pane-vertical"
12+
}

examples/3-pane.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"windows": [
3+
{
4+
"panes": [
5+
{
6+
"shell_command": [
7+
"cd /var/log",
8+
"ls -al | grep \\.log"
9+
]
10+
},
11+
"pwd",
12+
"pwd"
13+
],
14+
"shell_command_before": [
15+
"cd ~/"
16+
],
17+
"layout": "main-vertical",
18+
"window_name": "dev window"
19+
}
20+
],
21+
"session_name": "3-panes"
22+
}

examples/4-pane.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"windows": [
3+
{
4+
"panes": [
5+
{
6+
"shell_command": [
7+
"cd /var/log",
8+
"ls -al | grep \\.log"
9+
]
10+
},
11+
"pwd",
12+
"pwd",
13+
"pwd"
14+
],
15+
"shell_command_before": [
16+
"cd ~/"
17+
],
18+
"layout": "tiled",
19+
"window_name": "dev window"
20+
}
21+
],
22+
"session_name": "4-pane-split"
23+
}

tmuxp/cli.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,25 @@ def subcommand_convert(args):
210210
configparser = kaptan.Kaptan()
211211
configparser.import_config(configfile)
212212
newfile = fullfile.replace(ext, '.yaml')
213+
newconfig = configparser.export(
214+
'yaml', indent=2, default_flow_style=False
215+
)
213216
if query_yes_no('write config to %s?' % (newfile)):
217+
buf = open(newfile, 'w')
218+
buf.write(newconfig)
219+
buf.close()
214220
print ('written new config to %s' % (newfile))
215221
elif 'yaml' in ext:
216222
if query_yes_no('convert to <%s> to json?' % (fullfile)):
217223
configparser = kaptan.Kaptan()
218224
configparser.import_config(configfile)
219225
newfile = fullfile.replace(ext, '.json')
226+
newconfig = configparser.export('json', indent=2)
227+
print(newconfig)
220228
if query_yes_no('write config to <%s>?' % (newfile)):
229+
buf = open(newfile, 'w')
230+
buf.write(newconfig)
231+
buf.close()
221232
print ('written new config to <%s>.' % (newfile))
222233

223234

0 commit comments

Comments
 (0)