Skip to content
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

Remapping keys to a command that requires input #5499

Closed
Eloitor opened this issue Jan 11, 2023 · 6 comments
Closed

Remapping keys to a command that requires input #5499

Eloitor opened this issue Jan 11, 2023 · 6 comments
Labels
C-enhancement Category: Improvements

Comments

@Eloitor
Copy link
Contributor

Eloitor commented Jan 11, 2023

Hi,

I want to send lines from helix to tmux. For this I wrote this script:

$ cat tmux-send-stdin.sh
#!/bin/sh

# Get the session name from the command line argument
session="$1"

while read -r command; do
    tmux send-keys -t "$session" "$command" Enter
done

I wanted to create a map for shell_pipe_to such as

[keys.normal]
A-a = ["shell_pipe_to", "tmux-send-stdin.sh session-0"] 

output when running hx:

Bad config: No command named 'tmux-send-stdin.sh session-0' for key `keys.normal.A-a` at line 23 column 1
Press <ENTER> to continue with default config

The main problem is that shell_pipe_to requires the user to enter the program to use, but I don't know if this is possible to emulate with a keymap. I found this similar use case: https://www.reddit.com/r/HelixEditor/comments/xde3f1/remapping_keys_to_a_command_that_requires_input/

Is this possible to do currently? Is this planned? Is there a better solution to send commands to tmux?

@Eloitor Eloitor added the C-enhancement Category: Improvements label Jan 11, 2023
@archseer
Copy link
Member

This is why :pipe-to was added. You should be able to map to :pipe-to tmux-send-stdin.sh session-0

@Eloitor
Copy link
Contributor Author

Eloitor commented Jan 11, 2023

Thanks for the answer. I get

Bad config: No TypableCommand named ':pipe-to tmux-send-stdin.sh session-0' for key `keys.normal.A-a` at line 18 column 7
Press <ENTER> to continue with default config

I have version 22.12

@archseer
Copy link
Member

Looks like it's not in a release yet, it was merged after 22.12: #4931

@Eloitor
Copy link
Contributor Author

Eloitor commented Jan 13, 2023

While I'm waiting for the release I found this solution:

$ cat tmux-send-stdin.sh
#!/bin/sh

# Get the session name from the command line argument
session="$1"

while read -r command; do
    echo "$command"
    tmux send-keys -t "$session" "$command" Enter
done

And in the config:

[keys.normal]
A-a = ":pipe tmux-send-stdin.sh session-0"

@gabydd
Copy link
Member

gabydd commented Jan 14, 2023

Can we close this as it's already solved with pipe-to plus a duplicate of #1383 for keys that require input

@the-mikedavis
Copy link
Member

Closed by #4931

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Improvements
Projects
None yet
Development

No branches or pull requests

4 participants