Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
Signed-off-by: Tin Lai <[email protected]>
  • Loading branch information
soraxas committed Jul 21, 2024
1 parent 27e1058 commit 1b2fff5
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
35 changes: 35 additions & 0 deletions docs/configuration/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,41 @@ newer and tmux 3.0 or newer.
````

## `if` conditions

tmuxp enables one to optionally open windows / panes based on coditions. The `if` conditions can appears in the configuration for window or pane.

````{tab} YAML
```{literalinclude} ../../examples/if-conditions.yaml
:language: yaml
```
````

````{tab} JSON
```{literalinclude} ../../examples/if-conditions.json
:language: json
```
````

In the example, running the example

```console
$ tmuxp load examples/if-conditions.yaml
```

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

```console
$ show_htop=false tmuxp load examples/if-conditions.yaml
```

will insteads suppress the `htop` command pane and resulting in a different behaviour.

## Focusing

tmuxp allows `focus: true` for assuring windows and panes are attached /
Expand Down
49 changes: 49 additions & 0 deletions examples/if-conditions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"session_name": "if conditions test",
"environment": {
"Foo": "false",
"show_htop": "true"
},
"windows": [
{
"window_name": "window 1 ${ha} $Foo",
"if": {
"shell": "${Foo}"
},
"panes": [
{
"shell_command": [
"echo \"this shouldn't shows up\""
]
},
"echo neither should this $Foo"
]
},
{
"window_name": "window 2",
"panes": [
{
"if": {
"python": "1+1==3"
},
"shell_command": [
"echo the above is a false statement"
]
},
{
"shell_command": [
"echo no condition",
"python -m http.server"
]
},
{
"if": "${show_htop}",
"shell_command": [
"echo the above is a true statement (by default), but can be disabled on-demand",
"htop"
]
}
]
}
]
}
29 changes: 29 additions & 0 deletions examples/if-conditions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
session_name: if conditions test
environment:
Foo: 'false'
show_htop: 'true'
windows:
# the following would not shows up as it evaluates to false
- window_name: window 1 ${ha} $Foo
if:
shell: ${Foo}
panes:
- shell_command:
- echo "this shouldn't shows up"
- echo neither should this $Foo
- window_name: window 2
panes:
# should not shows up
- if:
python: 1+1==3
shell_command:
- echo the above is a false statement
# no if conditions
- shell_command:
- echo no condition
- python -m http.server
# display by default, but can be disabled by running `show_htop=false tmuxp load .....`
- if: ${show_htop}
shell_command:
- echo the above is a true statement (by default), but can be disabled on-demand
- htop

0 comments on commit 1b2fff5

Please sign in to comment.