Add support for send-input subcommand #12851

Open
opened 2026-01-31 03:26:43 +00:00 by claunia · 7 comments
Owner

Originally created by @ngmariusz on GitHub (Mar 3, 2021).

you can execute when creating tab

exp:
wt.exe -w 2 sp -V wsl.exe zsh -ic "l\; /bin/zsh"

but there is not way to execute when it's already created or i do sth wrong?

Environment

21322.1000
Windows 10 Feature Experience Pack 321.2906.0.3
wsl2
Linux DESKTOP-RRHRJSC 4.19.128-microsoft-standard #1 .... x86_64 x86_64 x86_64 GNU/Linux
Windows Terminal Preview 1.7.572.0

Steps to reproduce

wsl
wt.exe -w 2 focus-tab -t 3 /bin/bash -c 'ls'

Expected behavior

executes /bin/bash -c 'ls' in focused tab

or

introduce -exec flag that executes passed string

wt.exe -w 2 focus-tab -t 3 -exec "/bin/bash -c 'ls'"

Actual behavior

only focuses tab

Originally created by @ngmariusz on GitHub (Mar 3, 2021). you can execute when creating tab exp: `wt.exe -w 2 sp -V wsl.exe zsh -ic "l\; /bin/zsh"` but there is not way to execute when it's already created or i do sth wrong? # Environment 21322.1000 Windows 10 Feature Experience Pack 321.2906.0.3 wsl2 Linux DESKTOP-RRHRJSC 4.19.128-microsoft-standard #1 .... x86_64 x86_64 x86_64 GNU/Linux Windows Terminal Preview 1.7.572.0 # Steps to reproduce wsl wt.exe -w 2 focus-tab -t 3 /bin/bash -c 'ls' # Expected behavior executes `/bin/bash -c 'ls'` in focused tab or introduce -exec flag that executes passed string `wt.exe -w 2 focus-tab -t 3 -exec "/bin/bash -c 'ls'"` # Actual behavior only focuses tab
claunia added the Issue-TaskProduct-TerminalArea-Commandline labels 2026-01-31 03:26:43 +00:00
Author
Owner

@zadjii-msft commented on GitHub (Mar 3, 2021):

So, if I'm reading this correctly, what you're really looking for is the sendInput action, but as a subcommand on the commandline? So that when you already have an existing terminal instance, you could do

wt -w send-input ls

to send "ls" to the active pane. That makes sense to me. It's something we've been back and forth on in the past - I've been a little hesitant to allow other processes to "inject" input into terminal instances like this. That being said, we're not really pursuing mixed elevation anymore, so now I'm less worried about this.

What I am worried about is how we encode special characters. Not all shells support multi-line input, so putting a raw \n into the input might be tricky. It's easier to encode in json where you can just literally say "ls\n". A flag to say "please follow this input string with a \n" isn't a terrible idea, but then what if you want multiple commands? What if you want an arrow key? So we'd need to have a good way of encoding escape character in the input (regardless of shell).

@zadjii-msft commented on GitHub (Mar 3, 2021): So, if I'm reading this correctly, what you're really looking for is the `sendInput` action, but as a subcommand on the commandline? So that when you already have an existing terminal instance, you could do ``` wt -w send-input ls ``` to send "ls" to the active pane. That makes sense to me. It's something we've been back and forth on in the past - I've been a little hesitant to allow other processes to "inject" input into terminal instances like this. That being said, we're not really pursuing mixed elevation anymore, so now I'm less worried about this. What I am worried about is how we encode special characters. Not all shells support multi-line input, so putting a raw `\n` into the input might be tricky. It's easier to encode in json where you can just literally say `"ls\n"`. A flag to say "please follow this input string with a `\n`" isn't a terrible idea, but then what if you want multiple commands? What if you want an arrow key? So we'd need to have a good way of encoding escape character in the input (regardless of shell).
Author
Owner

@ngmariusz commented on GitHub (Mar 4, 2021):

Yes, thank you "send-input" is much better name;

As i understand encoding/escaping is well know problem

no long ago i was trying this ${selectedText} in vscode tasks ( https://code.visualstudio.com/docs/editor/variables-reference )
and it bited me couple of times but eventually i figured that out, we are developers after all ;)

...so perhaps accepting "multiline / etc input" in a smart way is yet another feature? and we could try how idea is working out in a wild.

to add more context of my use case

i'd like to have one monitor of multiple opened terminals only and pushing to chosen one with my ide shortcuts from another monitor

until remote control was released my scenario was

1. create command in editor (as i usually have there more context than terminal history) 
2. select 
3. copy 
4. change to desired terminal window (mostly with alt+tab 1-n times until got wanted one )
5. select desired tab
6. Paste
7. Go  back (mostly with alt+tab 1-n times until got wanted one)

with remote control currently i have

1. create command in editor (as i usually have there more context than terminal history) 
2. select 
3. copy 
4. with single shortcut -> select desired tab with know window id and tab index             
5. -
6. Paste
7. Go back (mostly with alt+tab 1-n times until got wanted one)

it's better but i need

1. create command in editor (as i usually have there more context than terminal history) 
2. select 
3. with single shortcut -> select desired tab with know window id and tab index and execute my selected string there        
4. -               
5. -
6. -
7. -  

there are also scenarios when command is derived entirely from context so if you'd create shortcut for this in your IDE you could

1. -
2. -
3. with single shortcut -> select desired tab with know window id and tab index and execute command is derived entirely from context there        
4. -               
5. -
6. -
7. -

i hope it's worth pursuing

also

it helps alot with work ergonomic ( and wrist pain ;) )

@ngmariusz commented on GitHub (Mar 4, 2021): Yes, thank you "send-input" is much better name; As i understand encoding/escaping is well know problem no long ago i was trying this ${selectedText} in vscode tasks ( https://code.visualstudio.com/docs/editor/variables-reference ) and it bited me couple of times but eventually i figured that out, we are developers after all ;) ...so perhaps accepting "multiline / etc input" in a smart way is yet another feature? and we could try how idea is working out in a wild. to add more context of my use case i'd like to have one monitor of multiple opened terminals only and pushing to chosen one with my ide shortcuts from another monitor until remote control was released my scenario was ``` 1. create command in editor (as i usually have there more context than terminal history) 2. select 3. copy 4. change to desired terminal window (mostly with alt+tab 1-n times until got wanted one ) 5. select desired tab 6. Paste 7. Go back (mostly with alt+tab 1-n times until got wanted one) ``` with remote control currently i have ``` 1. create command in editor (as i usually have there more context than terminal history) 2. select 3. copy 4. with single shortcut -> select desired tab with know window id and tab index 5. - 6. Paste 7. Go back (mostly with alt+tab 1-n times until got wanted one) ``` it's better but i need ``` 1. create command in editor (as i usually have there more context than terminal history) 2. select 3. with single shortcut -> select desired tab with know window id and tab index and execute my selected string there 4. - 5. - 6. - 7. - ``` there are also scenarios when command is derived entirely from context so if you'd create shortcut for this in your IDE you could ``` 1. - 2. - 3. with single shortcut -> select desired tab with know window id and tab index and execute command is derived entirely from context there 4. - 5. - 6. - 7. - ``` i hope it's worth pursuing also it helps alot with work ergonomic ( and wrist pain ;) )
Author
Owner

@joswr1ght commented on GitHub (Feb 14, 2022):

I'm not terribly concerned about multiline input, since you can stack multiple send-input commands to achieve the same goal. Perhaps it is a little less graceful, but it would allow for behavior similar to the current split-pane [commandline] syntax where \n is implied. The caller has to consider the requirements for whether the profile accepts any special characters sent.

I don't really see a use case for sending arrow keys as input (famous last words perhaps). My thinking is that this extends the precedent for functionality set by split-pane [commandline] for a lot of added flexibility.

@joswr1ght commented on GitHub (Feb 14, 2022): I'm not terribly concerned about multiline input, since you can stack multiple `send-input` commands to achieve the same goal. Perhaps it is a little less graceful, but it would allow for behavior similar to the current `split-pane [commandline]` syntax where `\n` is implied. The caller has to consider the requirements for whether the profile accepts any special characters sent. I don't really see a use case for sending arrow keys as input (famous last words perhaps). My thinking is that this extends the precedent for functionality set by `split-pane [commandline]` for a lot of added flexibility.
Author
Owner

@3N4N commented on GitHub (Jul 18, 2023):

This feature would be similar to tmux's send-keys action. It could be used in several ways, but I use it to send text from Vim to a REPL, basically setting up an ad-hoc IDE. (Yes Vim has embedded terminal now, but it cannot really replace a fully-functioning terminal.)

Wezterm also has a similar feature. It's called send-text.

@3N4N commented on GitHub (Jul 18, 2023): This feature would be similar to tmux's [`send-keys`][1] action. It could be used in several ways, but I use it to send text from Vim to a REPL, basically setting up an ad-hoc IDE. (Yes Vim has embedded terminal now, but it cannot really replace a fully-functioning terminal.) Wezterm also has a similar feature. It's called [`send-text`][2]. [1]: https://til.hashrocket.com/posts/ztxjgrqxhm-tmux-send-keys-to-pane [2]: https://wezfurlong.org/wezterm/cli/cli/send-text.html
Author
Owner

@noheromen commented on GitHub (Oct 12, 2023):

Any progress on this feature? I would like to have it too. Thanks

@noheromen commented on GitHub (Oct 12, 2023): Any progress on this feature? I would like to have it too. Thanks
Author
Owner

@zadjii-msft commented on GitHub (Oct 12, 2023):

Nope. We'll make sure to update this thread when there is. In the meantime, might I recommend the Subscribe button?
image
That way you'll be notified of any updates to this thread, without needlessly pinging everyone on this thread ☺️


I'm also still not sure how confident I feel about the ability for arbitrary exes to send arbitrary keystrokes to random shells. Maybe I'd feel more confident if it was an opt-in thing. Like, you need to turn on a special setting first to say "yep, I'm gonna do some scripting now" - though, if it was just in the settings.json, there's literally nothing that prevents malicious.exe from just changing the settings file itself.

@zadjii-msft commented on GitHub (Oct 12, 2023): Nope. We'll make sure to update this thread when there is. In the meantime, might I recommend the Subscribe button? ![image](https://user-images.githubusercontent.com/18356694/91237459-5cbb0c80-e700-11ea-9347-b9b1ec2813b1.png) That way you'll be notified of any updates to this thread, without needlessly pinging everyone on this thread ☺️ ---- I'm also still not sure how confident I feel about the ability for arbitrary exes to send arbitrary keystrokes to random shells. Maybe I'd feel more confident if it was an opt-in thing. Like, you need to turn on a special setting first to say "yep, I'm gonna do some scripting now" - though, if it was just in the settings.json, there's literally nothing that prevents `malicious.exe` from just changing the settings file itself.
Author
Owner

@einarpersson commented on GitHub (Jan 24, 2024):

I have really enjoyed working with WSL2 as a combination of Windows and Linux, but not being able to programmatically control the terminal app itself (including sending arbitrary input to it) feels limiting right now in a time of automation.

@einarpersson commented on GitHub (Jan 24, 2024): I have really enjoyed working with WSL2 as a combination of Windows and Linux, but not being able to programmatically control the terminal app itself (including sending arbitrary input to it) feels limiting right now in a time of automation.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#12851