Add a CLI executable for interacting with WT (wtcli.exe or something) #15696

Closed
opened 2026-01-31 04:45:48 +00:00 by claunia · 6 comments
Owner

Originally created by @3N4N on GitHub (Oct 26, 2021).

Description of the new feature/enhancement

With the command sendInput I can invoke shell commands with a key-binding. But that would send the input directly to the pane currently in focus. I want to invoke a shell command in the background. Kind of like how moveFocus command operates.

The specific use-case I want this for is navigating between vim and wt splits with one set of keybindings. As of now, I have to use two sets: one for vim (ctrl-h/j/k/l) and another for wt (ctrl-alt-h/j/k/l). I'm used to tmux and had a config which achieved exactly this purpose.

I can do half of the work from vim: when inside vim, I can check if there are other vim splits in the direction I want to move focus toward, and if not, I move over to the wt split in that direction, with the command wt -w 0 mf <direction>.

But that's only half the work. Now I have to configure wt to send the key to vim if the current wt split is harboring a vim spawn. In tmux, I had a way to --

  1. See if the focused split has vim open
    tmux display-message -p '#{pane_current_command}' | grep -iq vim
    
  2. Bind a key to a complex bash command
    bind -n C-h run \
             "((tmux list-panes -F '#F' | grep -q Z && tmux send-keys C-h) || \
             ((tmux display-message -p '#{pane_current_command}' | grep -iq vim \
               && tmux send-keys C-h) || tmux select-pane -L ))"
    

None of which is achievable in wt. Or I haven't found a way.

By the way, I noticed that the shell command wt -w 0 mf <direction> is slower than the native moveFocus command. And I think the shell variant even opens a new wt window for a split second. Why is that?

Originally created by @3N4N on GitHub (Oct 26, 2021). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> # Description of the new feature/enhancement <!-- A clear and concise description of what the problem is that the new feature would solve. Describe why and how a user would use this new functionality (if applicable). --> With the command `sendInput` I can invoke shell commands with a key-binding. But that would send the input directly to the pane currently in focus. I want to invoke a **shell** command in the background. Kind of like how `moveFocus` command operates. The specific use-case I want this for is navigating between vim and wt splits with one set of keybindings. As of now, I have to use two sets: one for vim (`ctrl-h/j/k/l`) and another for wt (`ctrl-alt-h/j/k/l`). I'm used to tmux and had a config which achieved exactly this purpose. I can do half of the work from vim: when inside vim, I can check if there are other vim splits in the direction I want to move focus toward, and if not, I move over to the wt split in that direction, with the command `wt -w 0 mf <direction>`. But that's only half the work. Now I have to configure wt to send the key to vim if the current wt split is harboring a vim spawn. In tmux, I had a way to -- 1. See if the focused split has vim open ```tmux tmux display-message -p '#{pane_current_command}' | grep -iq vim ``` 2. Bind a key to a complex bash command ```tmux bind -n C-h run \ "((tmux list-panes -F '#F' | grep -q Z && tmux send-keys C-h) || \ ((tmux display-message -p '#{pane_current_command}' | grep -iq vim \ && tmux send-keys C-h) || tmux select-pane -L ))" ``` None of which is achievable in wt. Or I haven't found a way. By the way, I noticed that the shell command `wt -w 0 mf <direction>` is slower than the native `moveFocus` command. And I think the shell variant even opens a new wt window for a split second. Why is that? <!-- # Proposed technical implementation details (optional) A clear and concise description of what you want to happen. -->
Author
Owner

@DHowett commented on GitHub (Oct 26, 2021):

Why is that?

I can't address the rest of this request right now, but I can probably explain this!

When you run an external application from within Vim, it runs it through vimrun. vimrun is a console application, and every console application gets a new console window.

@DHowett commented on GitHub (Oct 26, 2021): > Why is that? I can't address the rest of this request right now, but I can probably explain this! When you run an external application from within `Vim`, it runs it through `vimrun`. `vimrun` is a console application, and every console application gets a new console window.
Author
Owner

@3N4N commented on GitHub (Oct 27, 2021):

I'm not invoking that wt -w 0 mf command from inside vim, though. I'm invoking it from a normal cmd. Let me see if I can create a GIF.

Edit(27/09/2021): Here is a video.

https://user-images.githubusercontent.com/32037751/139111637-2e86cdcb-1611-4a39-9548-d5bdd914e139.mp4


Edit 2 (12/06/2022): As of now, it doesn't open a new windows-terminal. So that confusion is now beside the point. But -- and I'm sorry for pinging you again @DHowett -- have you guys added any functionality equivalent to tmux's pane_current_command which will let the user do stuff based on the program currently running on a pane?

@3N4N commented on GitHub (Oct 27, 2021): I'm not invoking that `wt -w 0 mf` command from inside vim, though. I'm invoking it from a normal cmd. Let me see if I can create a GIF. **Edit**(27/09/2021): Here is a video. https://user-images.githubusercontent.com/32037751/139111637-2e86cdcb-1611-4a39-9548-d5bdd914e139.mp4 --- **Edit 2 (12/06/2022)**: As of now, it doesn't open a new windows-terminal. So that confusion is now beside the point. But -- and I'm sorry for pinging you again @DHowett -- have you guys added any functionality equivalent to tmux's `pane_current_command` which will let the user do stuff based on the program currently running on a pane?
Author
Owner

@zadjii-msft commented on GitHub (Aug 22, 2022):

Hey sorry for leaving this untriaged for so long.

This thread's a little hard to parse, but I suppose ultimately the request here was for something like

wt display-message -p '#{pane_current_command}'

(and other commandline output about the state of wt)

That's kinda Hard at the moment. This comment has details: https://github.com/microsoft/terminal/issues/4570#issuecomment-586551445

We actually don't have an issue open tracking a separate CLI exe for interacting with wt. Coulda swore we did, but until we do, this thread is gonna become that one. Thanks!

@zadjii-msft commented on GitHub (Aug 22, 2022): Hey sorry for leaving this untriaged for so long. This thread's a little hard to parse, but I suppose ultimately the request here was for something like ``` wt display-message -p '#{pane_current_command}' ``` (and other commandline output about the state of `wt`) That's kinda **H**ard at the moment. This comment has details: https://github.com/microsoft/terminal/issues/4570#issuecomment-586551445 We actually don't have an issue open tracking a separate CLI exe for interacting with `wt`. Coulda swore we did, but until we do, this thread is gonna become that one. Thanks!
Author
Owner

@zadjii-msft commented on GitHub (Aug 22, 2022):

GAH no I found it. Sorry for the runaround!

/dup #7258

@zadjii-msft commented on GitHub (Aug 22, 2022): GAH no I found it. Sorry for the runaround! /dup #7258
Author
Owner

@ghost commented on GitHub (Aug 22, 2022):

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@ghost commented on GitHub (Aug 22, 2022): Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!
Author
Owner

@3N4N commented on GitHub (Nov 20, 2024):

@zadjii-msft

Hey sorry for leaving this untriaged for so long.

This thread's a little hard to parse, but I suppose ultimately the request here was for something like

wt display-message -p '#{pane_current_command}'

(and other commandline output about the state of wt)

That's kinda Hard at the moment. This comment has details: #4570 (comment)

We actually don't have an issue open tracking a separate CLI exe for interacting with wt. Coulda swore we did, but until we do, this thread is gonna become that one. Thanks!

Hi, I understand the issues (kind of). But even after two years I sorely miss Vim-Tmux-Navigator. So I decided to see if I can tweak the source code of Terminal myself.

I found the part where "moveFocus" action is handled (see below). Can I do something like the following (please 🥺) ?

std::shared_ptr<Pane> Pane::NavigateDirection(const std::shared_ptr<Pane> sourcePane, const FocusDirection& direction, const std::vector<uint32_t>& mruPanes)
{
  string tabTile = getTabTile();
  if (tabtitle.startsWith("Vim")) {
    // Send the pressed key to Vim and let Vim do with it what Vim wants
    sendKeyToTerminal(convertDirectionToPressedKey(direction));
    return nullptr;
  }
  // rest of the code
}
@3N4N commented on GitHub (Nov 20, 2024): @zadjii-msft > Hey sorry for leaving this untriaged for so long. > > This thread's a little hard to parse, but I suppose ultimately the request here was for something like > > ``` > wt display-message -p '#{pane_current_command}' > ``` > > (and other commandline output about the state of `wt`) > > That's kinda **H**ard at the moment. This comment has details: [#4570 (comment)](https://github.com/microsoft/terminal/issues/4570#issuecomment-586551445) > > We actually don't have an issue open tracking a separate CLI exe for interacting with `wt`. Coulda swore we did, but until we do, this thread is gonna become that one. Thanks! Hi, I understand the issues (kind of). But even after two years I sorely miss Vim-Tmux-Navigator. So I decided to see if I can tweak the source code of Terminal myself. I found the part where "moveFocus" action is handled (see below). Can I do something like the following (please 🥺) ? ``` std::shared_ptr<Pane> Pane::NavigateDirection(const std::shared_ptr<Pane> sourcePane, const FocusDirection& direction, const std::vector<uint32_t>& mruPanes) { string tabTile = getTabTile(); if (tabtitle.startsWith("Vim")) { // Send the pressed key to Vim and let Vim do with it what Vim wants sendKeyToTerminal(convertDirectionToPressedKey(direction)); return nullptr; } // rest of the code } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#15696