Skip to content

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

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

Closed
mcfongtw opened this issue Aug 18, 2017 · 11 comments
Closed

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

mcfongtw opened this issue Aug 18, 2017 · 11 comments

Comments

@mcfongtw
Copy link

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
Copy link
Member

tony commented Aug 18, 2017

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
Copy link
Author

mcfongtw commented Aug 19, 2017

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
Copy link
Member

tony commented Aug 19, 2017

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
Copy link
Author

mcfongtw commented Aug 19, 2017

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
Copy link

stale bot commented Nov 11, 2017

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.

@stale stale bot added the stale label Nov 11, 2017
@stale stale bot closed this as completed Nov 18, 2017
@tony tony reopened this Jul 25, 2020
@tony tony removed the stale label Jul 25, 2020
@soraxas
Copy link

soraxas commented Feb 11, 2021

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
Copy link

bedge commented Jun 11, 2021

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
Copy link
Member

tony commented Jun 11, 2021

@bedge I will look at this. Have you tried the backslash thing from here? #293 (comment)

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
Copy link

bedge commented Jun 13, 2021

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
Copy link
Member

tony commented Mar 12, 2022

@mcfonttw This is a good suggestion

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

@tony tony closed this as completed Mar 12, 2022
@tmux-python tmux-python locked and limited conversation to collaborators Mar 12, 2022
@tony tony added the duplicate label Mar 12, 2022
@tony
Copy link
Member

tony commented Mar 12, 2022

@thiagowfx

1.10.0b1 superseded by 1.10.0b3+

Live in 1.10.0b1 pypi branch

pip install --user --upgrade tmuxp==1.10.0b1

or pipx install [email protected] 'tmuxp==1.10.0b1' then [email protected] load <yaml file>

docs: skip command execution

session_name: Should not execute
windows:
- panes:
  - shell_command: echo "___$((1 + 3))___"
    enter: false

See v1.10.0b3: #53 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants