Terminal: Feature Request: multi-commanding

Created on 3 Sep 2019  路  5Comments  路  Source: microsoft/terminal

Description of the new feature/enhancement

Problem
The following pattern is inefficient from the command-line and often requires an alternate GUI tool:

  1. Run a command that produces a list
  2. For each entry in the list, run another command

For example:

  1. git status (say we are interested in the conflict list)
  2. For each file in the list above, "vi filename" to resolve merge conflicts
  3. For each file in the list above, "git add"

In practice, this pattern has so much duplicate typing from the command-line, often people are required to use a GUI tool instead.

Proposal
Add a multi-command feature so the list work flow becomes:

  1. Run a command that produces the list (eg. git status)
  2. Alt-select list of interesting files
  3. Type "git add {special key}" to enter multi-command mode which replicates the current typed line for each row in the selection.
  4. Either type more commands afterwards or hit {enter} after to run multiple commands one at a time in the order they appear in the row selection.
Area-Interaction Issue-Question Product-Terminal Resolution-Answered

All 5 comments

Sounds to me like what you're looking for is the xargs linux tool. A sample using wsl to achieve your above use case:

image

xargs is close but has problems:

  1. You need to use something like sed which is slower than alt-selection .
  2. It executes commands without you knowing what it will execute ahead of time. It's the same fundamental problem of "!" where it goes executes something and you hope it's what you expected. You can turn on prompting, but that slows down the flow.

The proposal is more like the multicursor feature in editors. For the above example, one multicommanding typing option would be:

git status
git add {ctrl-alt-select filelist} \

Here I added ctrl-alt-select as a way to specify multi-command mode, but you could also do a keybinding although there's risk of conflict with key bindings.

Honestly with sounds like a _shell_ feature to me, not a _terminal_ feature. The terminal would need to know some pretty intimate details about the shell that's running for this to work in a general sense. How would this functionality work in something like vim or emacs? What about tmux, or even ssh?

That being said, with the tight coupling to the act of _selecting_, something wholly owned by the terminal, it doesn't seem like a purely _shell_ feature only. You'd almost need a dedicated terminal+shell application, like the Powershell ISE.

Maybe I'm wrong on this, and someone can clarify how this could be done in a generic way.

@zadjii-msft, I think you are right that it's a shell feature and not a terminal feature. I think your xargs suggestion was close as well.

I think I can accomplish this in powershell for example by writing an xargs like command that reads clipboard, likely needs to convert forward slashes to backslashes, and just replays commands. So, flow would become:

git status
{alt-select filelist}
ClipArgs git add

For Linux, you can kind of do this with xargs + xclip, although, xclip doesn't seem to work with WSL.

For emacs, this essentially becomes a way to replace a selection with an prefix/postfix version of the selection which isn't necessary. vi has risk of interacting badly with vi modes and also doesn't need the prefix/postfix feature.

@AshrafMichail Good to hear. Closing this issue as you have a work-around.

Was this page helpful?
0 / 5 - 0 ratings