Allow sendInput to have promptable sections for further completion #17271

Open
opened 2026-01-31 05:37:28 +00:00 by claunia · 0 comments
Owner

Originally created by @zadjii-msft on GitHub (Apr 18, 2022).

This is like half a showerthought.

Probably refer to

What if sendInput could have like, a ${prompt} section in it, that then had the terminal prompt you to complete that section before actually doing the whole sendInput? So you could have like (for trivial example):

"command": 
{
    "action": "sendInput",
    "input": "git checkout ${prompt}"
},

Okay now hear me out for where we get extra crazy.

Crazy idea A

You can label these sections, and we'd fill in subsequent ones if you fill in the first:

"command": 
{
    "action": "sendInput",
    "input": "git checkout ${prompt branch} & echo 'switched to branch ${prompt branch}'"
},

This part is definitely inspired by macros in Sublime Text, where I know you can label individual bits as being the same thing.

Crazy idea B

We annotate these sections, and try to provide intelligent completions for them. Like say

"command": 
{
    "action": "sendInput",
    "input": "robocopy ${prompt source:dir} ${prompt target:dir} /mir"
},

So when we see :dir, we know that we're supposed to autofill a path into there. That could even be tied into the shell location (OSC9;9) to provide context-sensitive completion.

Crazy idea C

Building on B, what if apps could provide their own completions to us?

"command": 
{
    "action": "sendInput",
    "input": "git checkout ${prompt branch:git-branch} & echo 'switched to branch ${prompt branch}'"
},

// elsewhere in the settings
"git-branch": "git for-each-ref --format=%(refname:short) refs/heads/"

addenda

  • Are these not basically just shell aliases?
  • Would this not just make more sense as a shell feature? The shell already knows things about where the CWD is. It can do directories and stuff. Maybe it makes more sense to just let WT conveniently manage your aliases for different shells?
  • Obviously CMD is terrible so it'll never get anything like this.
  • Could we make them CWD-specific? Like, context sensitive?

Crazy idea D

basically like C, but more scriptable?

I propose to extend sendInput command (#3799) . At present, it allows to pass String input, which should be displayed on the terminal. I want to execute a code and display the result, instead of static text.

For example, I want to insert a current git branch to the current terminal cursor position. I can get the name with help git rev-parse --abbrev-ref HEAD. So, I would like to have the following hotkey in the terminal:

{
  "command": {
    "action": "sendInput",
    "input": $(git rev-parse --abbrev-ref HEAD), or ./get-branch-name.exe
  },
  "keys": "ctrl+k"
}

At present, I cannot do it, because input accepts only strings. There are a few workarounds, like, "input": "git rev-parse --abbrev-ref HEAD| Set-Clipboard\r, but they don't allow to insert needed input in place.

Crazy idea E

What if it was just the .vscode/tasks.json syntax?

Originally created by @zadjii-msft on GitHub (Apr 18, 2022). This is like half a showerthought. Probably refer to * #1595 ~#12862~ * #12861 What if `sendInput` could have like, a `${prompt}` section in it, that then had the terminal prompt you to complete that section before actually doing the whole `sendInput`? So you could have like (for trivial example): ```json "command": { "action": "sendInput", "input": "git checkout ${prompt}" }, ``` Okay now hear me out for where we get extra crazy. ### Crazy idea A You can label these sections, and we'd fill in subsequent ones if you fill in the first: ```json "command": { "action": "sendInput", "input": "git checkout ${prompt branch} & echo 'switched to branch ${prompt branch}'" }, ``` This part is definitely inspired by macros in Sublime Text, where I know you can label individual bits as being the same thing. ### Crazy idea B We annotate these sections, and try to provide intelligent completions for them. Like say ```json "command": { "action": "sendInput", "input": "robocopy ${prompt source:dir} ${prompt target:dir} /mir" }, ``` So when we see `:dir`, we know that we're supposed to autofill a path into there. That could even be tied into the shell location (`OSC9;9`) to provide context-sensitive completion. ### Crazy idea C Building on **B**, what if apps could provide their own completions to us? ```jsonc "command": { "action": "sendInput", "input": "git checkout ${prompt branch:git-branch} & echo 'switched to branch ${prompt branch}'" }, // elsewhere in the settings "git-branch": "git for-each-ref --format=%(refname:short) refs/heads/" ``` ### addenda * Are these not basically just shell aliases? * Would this not just make more sense as a shell feature? The shell already knows things about where the CWD is. It can do directories and stuff. Maybe it makes more sense to just let WT conveniently manage your aliases for different shells? * Obviously CMD is terrible so it'll never get anything like this. * Could we make them CWD-specific? Like, context sensitive? ### Crazy idea D basically like **C**, but more scriptable? > I propose to extend [sendInput](https://learn.microsoft.com/en-us/windows/terminal/customize-settings/actions#send-input) command (#3799) . At present, it allows to pass `String` input, which should be displayed on the terminal. I want to execute a code and display the result, instead of static text. > > For example, I want to insert a current `git` branch to the current terminal cursor position. I can get the name with help `git rev-parse --abbrev-ref HEAD`. So, I would like to have the following hotkey in the terminal: > > ``` > { > "command": { > "action": "sendInput", > "input": $(git rev-parse --abbrev-ref HEAD), or ./get-branch-name.exe > }, > "keys": "ctrl+k" > } > ``` > > At present, I cannot do it, because `input` accepts only strings. There are a few workarounds, like, `"input": "git rev-parse --abbrev-ref HEAD| Set-Clipboard\r`, but they don't allow to insert needed input in place. ### Crazy idea E What if it was just the [`.vscode/tasks.json`](https://github.com/microsoft/terminal/blob/main/.vscode/tasks.json) syntax?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#17271