Skip to content

Command level enter: false #755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
session_name: Should not execute
windows:
- panes:
- shell_command: echo "___$((1 + 3))___"
- shell_command:
- cmd: echo "___$((1 + 3))___"
enter: false

# pane-wide skip
- shell_command:
- echo "___$((1 + 3))___"
enter: false
```

Expand Down Expand Up @@ -71,7 +77,7 @@

- #752: Command structure (internal API)

To pave the way for per-command options such as `enter: false` (#52), commands are now a different format:
To pave the way for per-command options such as `enter: false` (#53), commands are now a different format:

Before, [`str`](str):

Expand Down
24 changes: 22 additions & 2 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,9 @@ This will add the `shell_command` to the bash history in the pane.
## Skip command execution

```{versionadded} 1.10.0b1
`enter: false` option. This is only available at the pane (not command level)
until [#751](https://github.com/tmux-python/tmuxp/issues/751) is published.
`enter: false` option. Pane-level support.
```{versionadded} 1.10.0b3
Support command-level skipping.
```

Omit sending {kbd}`enter` to key commands. Equivalent to
Expand All @@ -356,6 +357,25 @@ Omit sending {kbd}`enter` to key commands. Equivalent to

````

````{tab} YAML (pane-level)

```{literalinclude} ../examples/skip-send-pane-level.yaml
:language: yaml

```

````

````{tab} JSON (pane-level)

```{literalinclude} ../examples/skip-send-pane-level.json
:language: json

```

````


## Window Index

You can specify a window's index using the `window_index` property. Windows
Expand Down
20 changes: 20 additions & 0 deletions examples/skip-send-pane-level.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"session_name": "Skip all pane commands",
"windows": [
{
"panes": [
{
"shell_command": "echo \"___$((1 + 3))___\"",
"enter": false
},
{
"shell_command": [
"echo \"___$((1 + 3))___\"\\;",
"echo \"___$((1 + 3))___\""
],
"enter": false
}
]
}
]
}
9 changes: 9 additions & 0 deletions examples/skip-send-pane-level.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
session_name: Skip all pane commands
windows:
- panes:
- shell_command: echo "___$((1 + 3))___"
enter: false
- shell_command:
- echo "___$((1 + 3))___"\;
- echo "___$((1 + 3))___"
enter: false
11 changes: 8 additions & 3 deletions examples/skip-send.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
{
"session_name": "Should not execute",
"session_name": "Skip command execution (command-level)",
"windows": [
{
"panes": [
{
"shell_command": "echo \"___$((1 + 3))___\"",
"enter": false
"shell_command": [
"echo \"___$((11 + 1))___\"",
{
"cmd": "echo \"___$((1 + 3))___\"",
"enter": false
}
]
}
]
}
Expand Down
10 changes: 7 additions & 3 deletions examples/skip-send.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
session_name: Should not execute
session_name: Skip command execution (command-level)
windows:
- panes:
- shell_command: echo "___$((1 + 3))___"
enter: false
- shell_command:
# You can see this
- echo "___$((11 + 1))___"
# This is skipped
- cmd: echo "___$((1 + 3))___"
enter: false
58 changes: 58 additions & 0 deletions tests/test_workspacebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,60 @@ def test_find_current_active_pane(server, monkeypatch):
- panes:
- shell_command:
- echo "___$((1 + 3))___"
"""
),
"___4___",
True,
],
[
textwrap.dedent(
"""
session_name: Should not execute
windows:
- panes:
- shell_command:
- cmd: echo "___$((1 + 3))___"
enter: false
"""
),
"___4___",
False,
],
[
textwrap.dedent(
"""
session_name: Should not execute
windows:
- panes:
- shell_command:
- cmd: echo "___$((1 + 3))___"
enter: false
"""
),
"___4___",
False,
],
[
textwrap.dedent(
"""
session_name: Should execute
windows:
- panes:
- shell_command: echo "___$((1 + 3))___"
"""
),
"___4___",
True,
],
[
textwrap.dedent(
"""
session_name: Should execute
windows:
- panes:
- shell_command:
- cmd: echo "other command"
- cmd: echo "___$((1 + 3))___"
"""
),
"___4___",
Expand All @@ -930,6 +984,10 @@ def test_find_current_active_pane(server, monkeypatch):
"pane_enter_false_longform",
"pane_enter_default_shortform",
"pane_enter_default_longform",
"pane_command_enter_false_shortform",
"pane_command_enter_false_longform",
"pane_command_enter_default_shortform",
"pane_command_enter_default_longform",
],
)
def test_load_workspace_enter(
Expand Down
3 changes: 2 additions & 1 deletion tmuxp/workspacebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,9 @@ def get_pane_shell():
suppress = True

enter = pconf.get("enter", True)

for cmd in pconf["shell_command"]:
enter = cmd.get("enter", enter)

p.send_keys(cmd["cmd"], suppress_history=suppress, enter=enter)

if "focus" in pconf and pconf["focus"]:
Expand Down