Skip to content

Commit 1b2fff5

Browse files
committed
add docs
Signed-off-by: Tin Lai <tin@tinyiu.com>
1 parent 27e1058 commit 1b2fff5

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed

docs/configuration/examples.md

+35
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,41 @@ newer and tmux 3.0 or newer.
287287
288288
````
289289

290+
## `if` conditions
291+
292+
tmuxp enables one to optionally open windows / panes based on coditions. The `if` conditions can appears in the configuration for window or pane.
293+
294+
````{tab} YAML
295+
296+
```{literalinclude} ../../examples/if-conditions.yaml
297+
:language: yaml
298+
299+
```
300+
````
301+
302+
````{tab} JSON
303+
304+
```{literalinclude} ../../examples/if-conditions.json
305+
:language: json
306+
307+
```
308+
309+
````
310+
311+
In the example, running the example
312+
313+
```console
314+
$ tmuxp load examples/if-conditions.yaml
315+
```
316+
317+
should produce **only** a window with upper and lower split panes (others should have `if` conditions that evaluates to false). This example allows for on-demand pane showing, where
318+
319+
```console
320+
$ show_htop=false tmuxp load examples/if-conditions.yaml
321+
```
322+
323+
will insteads suppress the `htop` command pane and resulting in a different behaviour.
324+
290325
## Focusing
291326

292327
tmuxp allows `focus: true` for assuring windows and panes are attached /

examples/if-conditions.json

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"session_name": "if conditions test",
3+
"environment": {
4+
"Foo": "false",
5+
"show_htop": "true"
6+
},
7+
"windows": [
8+
{
9+
"window_name": "window 1 ${ha} $Foo",
10+
"if": {
11+
"shell": "${Foo}"
12+
},
13+
"panes": [
14+
{
15+
"shell_command": [
16+
"echo \"this shouldn't shows up\""
17+
]
18+
},
19+
"echo neither should this $Foo"
20+
]
21+
},
22+
{
23+
"window_name": "window 2",
24+
"panes": [
25+
{
26+
"if": {
27+
"python": "1+1==3"
28+
},
29+
"shell_command": [
30+
"echo the above is a false statement"
31+
]
32+
},
33+
{
34+
"shell_command": [
35+
"echo no condition",
36+
"python -m http.server"
37+
]
38+
},
39+
{
40+
"if": "${show_htop}",
41+
"shell_command": [
42+
"echo the above is a true statement (by default), but can be disabled on-demand",
43+
"htop"
44+
]
45+
}
46+
]
47+
}
48+
]
49+
}

examples/if-conditions.yaml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
session_name: if conditions test
2+
environment:
3+
Foo: 'false'
4+
show_htop: 'true'
5+
windows:
6+
# the following would not shows up as it evaluates to false
7+
- window_name: window 1 ${ha} $Foo
8+
if:
9+
shell: ${Foo}
10+
panes:
11+
- shell_command:
12+
- echo "this shouldn't shows up"
13+
- echo neither should this $Foo
14+
- window_name: window 2
15+
panes:
16+
# should not shows up
17+
- if:
18+
python: 1+1==3
19+
shell_command:
20+
- echo the above is a false statement
21+
# no if conditions
22+
- shell_command:
23+
- echo no condition
24+
- python -m http.server
25+
# display by default, but can be disabled by running `show_htop=false tmuxp load .....`
26+
- if: ${show_htop}
27+
shell_command:
28+
- echo the above is a true statement (by default), but can be disabled on-demand
29+
- htop

0 commit comments

Comments
 (0)