tmux-python / tmuxp

🖥️ Session manager for tmux, build on libtmux.
https://tmuxp.git-pull.com/
MIT License
4.08k stars 232 forks source link

Equivalence to send-keys without hitting 'enter' #293

Closed mcfongtw closed 2 years ago

mcfongtw commented 7 years ago

Hi,

I am really impressed with the flexibility of this tool working cohesively with tmux. Good work!

I have tried shell_command / shell_command_before, and both of them would execute the command immediately. I am just wondering if there is / will be a syntax that supports send-key without hitting the 'enter'? This might be useful when we have some heavy-weight command ready, but do not execute it unless user specifically hit 'enter'.

Thanks!

tony commented 7 years ago

Hi,

We have it in libtmux (send_keys() with enter=False). However, it's not a feature in the tmuxp language.

http://libtmux.git-pull.com/en/latest/api.html#libtmux.Pane.send_keys

You could suggest a Pull Request. It may be good to know what you think the markup would look like in the config for a command that's not entered fully.

mcfongtw commented 7 years ago

Hi, @tony

Thanks for your reply.

I am migrating some of my tmuxifier layouts to tmuxp yaml. There is an option to execute command (run_cmd) or paste command only (send_keys) to the pane in tmuxifier. In my scenario, I found the send_keys command is useful for resource-consuming commands and requires further confirmation to execute, i.e. linux perf commands. I like having those commands automated with tmuxifier / tmup due to complexity of cli arguments.

I might be able to help providing a PR, if there is any guideline to dev for this project.

Regards,

tony commented 7 years ago

I think before a PR, we should discuss what a command without hitting enter should look like in the YAML/JSON config. It should be something unambiguous.

By the way, (as a temporary workaround), have you try making your last command have \ at the end, and starting a session?

e.g.

session_name: unreturned command
windows:
  - window_name: my test window
    panes:
      - shell_command:
        - echo first command
        - echo have last command unsent \

Then you can hit ^H/backspace and return.

idea: We could also make the default behavior of a \ in shell_command delete the \, and send enter=False. To use default behavior (what \ at the end gives now), they can escape it \\.

mcfongtw commented 7 years ago

Hi,

Adding backslash at the end of command line seems to work all right.

I see your points now. The original idea of mine was simply to add another command syntax i.e. paste_command (internally calling libtmux.send_keys with enter=False), solely for this purpose. I haven not considered the scenario of executing list of commands. However, from my own use case, the purpose is not to 'execute' the command, but to 'prepare' it. Thus, it is not necessary to follow the form of performing list of commands as shell_command does, perhaps?

Regards,

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This bot is used to handle issues where the issue hasn't been discussed or has gone out of date. If an issue isn't resolved and handled in a certain period of time, it may be closed. If you would like your issue re-opened, please create a fresh issue with the latest, up to date information and mention this issue in it.

soraxas commented 3 years ago

Hi I was also looking for something similar to what the OP wanted. I'm just wondering if the mentioned API

We have it in libtmux (send_keys() with enter=False). However, it's not a feature in the tmuxp language.

http://libtmux.git-pull.com/en/latest/api.html#libtmux.Pane.send_keys

ever exposed in tmuxp yet?

Thanks for this wonderful tool eitherway!

bedge commented 3 years ago

At least the rate at which people are finding this ticket is increasing.... It does appear to be the sole remaining feature that may require holding on to raw tmux or tmuxinator.

tony commented 3 years ago

@bedge I will look at this. Have you tried the backslash thing from here? https://github.com/tmux-python/tmuxp/issues/293#issuecomment-323526543

I'm surprised we don't have this added

@soraxas @mcfongtw @bedge and anyone else interested: Any suggestion of what a command without enter (e.g. send_keys(cmd, enter=False) would look like in the syntax? (Without breaking earlier configurations, ideally?)

Perhaps:

- cmd: echo 'hello'
  send_keys: false

Also, has anyone tried literal style with tmux before? https://yaml.org/spec/1.2/spec.html#id2795688, https://stackoverflow.com/a/38747606

Folded block style? https://yaml.org/spec/1.2/spec.html#id2796251, https://stackoverflow.com/a/47018417

Side note: Outside this issue, if anyone would like to add some doc examples using folded block and and literal styles, that'd be welcomed :)

bedge commented 3 years ago

My use case is a bit different as I'm not looking to feed keys to a shell, but rather to the tmux instance.

eg: connect to some number of slaves, then perform some common tasks.

session_name: jenkins

environment:
    pw: password

windows:
- window_name: slaves
  layout: tiled
  panes:
    - shell_command:
      - ssh slave1
    - shell_command:
      - ssh slave2

after_commands (analogous to the before_commands_shell, but not to the shell?)
- tmux_commands - fed to the tmux instance, not to any specific shell.
  - pane sync on
  - send-keys "Password" Enter
  - send-keys "sudo su jenkins" Enter
  - send-keys "Password" Enter
  - pane sync off

The after_commands bit would affect all open windows because of the pane sync on.

Even better would be some embedded expect variant as send-keys is open loop, there's no way to control pacing.

after_commands
- tmux_commands
  - pane sync on
  - waitfor "password:"
  - send-keys "Password" Enter
  - send-keys "sudo su jenkins" Enter
  - waitfor "password:"
  - send-keys "Password" Enter
  - pane sync off

Granted the pane sync on bit isn't needed if one scripts this per shell session.

I suppose this could be done kicking off an expect script within each shell session with no tmuxp changes. I'll try that and see if it's feasible.

tony commented 2 years ago

@mcfonttw This is a good suggestion

As a next step I am moving this to the oldest issue to consolidate things: #53

tony commented 2 years ago

@thiagowfx

1.10.0b1 superseded by 1.10.0b3+ Live in 1.10.0b1 [pypi](https://pypi.org/project/tmuxp/1.10.0b1/) [branch](https://github.com/tmux-python/tmuxp/tree/v1.10.0b1) `pip install --user --upgrade tmuxp==1.10.0b1` or `pipx install --suffix=@1.10.0b1 'tmuxp==1.10.0b1'` then `tmuxp@1.10.0b1 load ` docs: [skip command execution](https://tmuxp.git-pull.com/examples.html#skip-command-execution) ```yaml session_name: Should not execute windows: - panes: - shell_command: echo "___$((1 + 3))___" enter: false ```

See v1.10.0b3: https://github.com/tmux-python/tmuxp/issues/53#issuecomment-1066200134