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

Add support for wt.exe to run commands in an existing Terminal Window #4472

Closed
Danthar opened this issue Feb 5, 2020 · 69 comments · Fixed by #8898
Closed

Add support for wt.exe to run commands in an existing Terminal Window #4472

Danthar opened this issue Feb 5, 2020 · 69 comments · Fixed by #8898
Assignees
Labels
Area-Commandline wt.exe's commandline arguments Area-Server Down in the muck of API call servicing, interprocess communication, eventing, etc. Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Milestone

Comments

@Danthar
Copy link

Danthar commented Feb 5, 2020

Description of the new feature/enhancement

I have been playing around with Jetbrains Rider, and when i start a console app with that IDE, it runs the console window inside a docked window in the IDE.

So what i was thinking. How cool would it be, if Windows Terminal allows external applications to start a new Console window in the currently running Windows Terminal instance.

That way whether its VisualStudio or Rider, those IDE's can be configured to start a new Console window inside the Windows Terminal instance.

The way i see this working is: I press F5/ctrl-F5 in visual studio, and instead of opening a new cmd console window, a new tab appears in my running Windows Terminal instance.

@Danthar Danthar added the Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. label Feb 5, 2020
@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Feb 5, 2020
@lostmsu
Copy link

lostmsu commented Feb 6, 2020

Yes, please. There's a Visual Studio extension, that lets you open command line in the current project folder. I set it to launch wt.exe, and it always creates a new window, but I'd love if I could pass a parameter to wt.exe, so that if Terminal is already running, it would be activated a new tab would open there instead.

@DHowett-MSFT
Copy link
Contributor

Thanks for the request! I thought we had a backlog item for "allow remote control of a terminal" (like: wt.exe could --remote to control another open instance and add tabs or whatever), but it looks like we don't.

This is now that issue. Triaged into backlog.

/cc @zadjii-msft: I may be wrong in not finding a "remote control" issue

@DHowett-MSFT DHowett-MSFT added this to the Terminal Backlog milestone Feb 7, 2020
@DHowett-MSFT DHowett-MSFT added Area-Server Down in the muck of API call servicing, interprocess communication, eventing, etc. Product-Terminal The new Windows Terminal. labels Feb 7, 2020
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Feb 7, 2020
@DHowett-MSFT DHowett-MSFT removed the Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting label Feb 7, 2020
@DHowett-MSFT DHowett-MSFT changed the title Allow remote applications to start a new shell inside an active WindowsTerminal instance Allow remote applications to start a new shell inside an active WindowsTerminal instance (remote control?) Feb 7, 2020
@DHowett-MSFT
Copy link
Contributor

Partially supported by #2080.

@zadjii-msft
Copy link
Member

This was briefly mentioned in this spec

Future considerations

  • These are some additional argument ideas which are dependent on other features
    that might not land for a long time. These features were still considered as a
    part of the design of this solution, though their implementation is purely
    hypothetical for the time being.
    • Instead of launching a new Windows Terminal window, attach this new
      terminal to an existing one. This would require the work outlined in
      [Spec for tab tear off and default app #2080], so support a "manager" process that could coordinate sessions
      like this.
      • This would be something like wt --session [some-session-id] [commands], where --session [some-session-id] would tell us that
        [more-commands] are intended for the given other session/window.
        That way, you could open a new tab in another window with wt --session 0 cmd.exe (for example).
    • list-sessions: A command to display all the active Windows terminal
      instances and their session ID's, in a way compatible with the above
      command. Again, heavily dependent upon the implementation of [Spec for tab tear off and default app #2080].

Which yea is part of #2080, but I don't think has it's own issue.

@Rumbah2
Copy link

Rumbah2 commented Feb 14, 2020

Wow, I was just thinking about "starting a new program/task in any existing windows terminal window" or a "single instance mode" to populate a WT window with multiple tasks via CLI would be great.
But something like sessions would be even better and more flexible.

But I admit that I'd prefer a "quick and dirty" single instance mode in the near future over a flexible session management in the distant future (as I could use it sooner than later).

@zadjii-msft zadjii-msft changed the title Allow remote applications to start a new shell inside an active WindowsTerminal instance (remote control?) Add support for wt.exe to run commands in an existing Terminal Window Feb 20, 2020
@zadjii-msft zadjii-msft added the Area-Commandline wt.exe's commandline arguments label Feb 20, 2020
@mreymann
Copy link

mreymann commented Mar 12, 2021

I didn't even know calling Windows binaries works at all! ;-) cmd.exe works, wt.exe doesn't:

[12:14:33][pigpen@box:~]$ which wt.exe
/mnt/c/Users/<USER>/AppData/Local/Microsoft/WindowsApps/wt.exe

[12:15:03][pigpen@box:~]$ strace wt.exe
execve("/mnt/c/Users/<USER>/AppData/Local/Microsoft/WindowsApps/wt.exe", ["wt.exe"], 0x7ffff5c7a1b0 /* 24 vars */) = -1 ENOEXEC (Exec format error)
strace: exec: Exec format error
+++ exited with 1 +++

@fredrikhr
Copy link

@mreymann Yeah, this is caused by this AppContainer isolation layer of Appx Packages (Microsoft Store apps) and how their executables are placed in the %LOCALAPPDATA%\Microsoft\WindowsApps folder. The files in there both are and are not there or at least are not really executable, but the Windows OS does some weird magic trick to actually start the correct binary from wherever the App is actully installed. Which is why starting the exe from a windows-shell starting point works, whereas from a WSL2-starting point it does not.

Would be interesting whether the technology used in WSL1 leads to this actually working, or not...

ghost pushed a commit that referenced this issue Mar 17, 2021
This finishes the implementation of `--window` to also accept a string
as the "name" of the window. So you can say 

```sh
wt -w foo new-tab
wt -w foo split-pane
```

and have both those commands execute in the same window, the one named
"foo". This is just slightly more ergonomic than manually using the IDs
of windows. In the future, I'll be working on renaming windows, and
displaying these names. 

> #### `--window,-w <window-id>`
> Run these commands in the given Windows Terminal session. This enables opening
> new tabs, splits, etc. in already running Windows Terminal windows.
> * If `window-id` is `0`, run the given commands in _the current window_.
> * If `window-id` is a negative number, or the reserved name `new`, run the
>   commands in a _new_ Terminal window.
> * If `window-id` is the ID or name of an existing window, then run the
>   commandline in that window.
> * If `window-id` is _not_ the ID or name of an existing window, create a new
>   window. That window will be assigned the ID or name provided in the
>   commandline. The provided subcommands will be run in that new window.
> * If `window-id` is omitted, then obey the value of `windowingBehavior` when
>   determining which window to run the command in.

Before this PR, I think we didn't actually properly support assigning
the id with `wt -w 12345`. If `12345` didn't exist, it would make a new
window, but just assign it the next id, not assign it 12345.

## References
* #4472, #8135
* https://github.com/microsoft/terminal/projects/5

## Validation Steps Performed
Ran tests
Messed with naming windows, working as expected.

Closes https://github.com/microsoft/terminal/projects/5#card-51431478
@JenuelDev
Copy link

If someone needs the commands to create a new tab (and not open a new window) from a context menu item are:

(if you are already in the directory):
wt -w 0 nt

(and if you click on the directory):
wt -w 0 nt -d %1

You can add these commands in the respective registry of each item (or in a new one)

this really works it open a new tab, the problem is the directory was reset,.. hoping that I open a new tab, it will be at the same directory in my working project.

@santanaruben
Copy link

@BroJenuel
0
1

The first case was a modification.
The second one I had to create.

ghost pushed a commit that referenced this issue Apr 21, 2021
### ⇒ [doc link](https://github.com/microsoft/terminal/blob/dev/migrie/s/653-quake-mode/doc/specs/%23653%20-%20Quake%20Mode/%23653%20-%20Quake%20Mode.md) ⇐

## Summary of the Pull Request

After reading through 114+ comments in #653 and related issues, I think I've finally wrapped my head around all the possible scenarios for quake mode. <!-- Speak now or forever hold your peace. --> This also includes "minimize to tray", because the two are a powerful combination. With the work already prototyped in [`dev/migrie/f/653-QUAKE-MODE`](https://github.com/microsoft/terminal/tree/dev/migrie/f/653-QUAKE-MODE), [I'm starting to believe](https://j.gifs.com/58vKNx.gif) that we could actually land this in 2.0.


### Abstract

> Many existing terminals support a feature whereby a user can press a keybinding
> anywhere in the OS, and summon their terminal application. Oftentimes the act of
> summoning this window is accompanied by a "dropdown" animation, where the window
> slides in to view from the top of the screen. This global summon action is often
> referred to as "quake mode", a reference to the videogame Quake who's console
> slid in from the top.
> 
> This spec addresses both of the following two issues:
> * "Quake Mode" ([#653])
> * "Minimize to tray" ([#5727])


## PR Checklist
* [x] Specs: #653, #5727
* [x] References: #5000, #4472, #2227, #7240, #8135
* [x] I work here

## Detailed Description of the Pull Request / Additional comments
_\*<sup>\*</sup><sub>\*</sub> read the spec  <sub>\*</sub><sup>\*</sup>\*_
zadjii-msft added a commit that referenced this issue Aug 25, 2021
### ⇒ [doc link](https://github.com/microsoft/terminal/blob/dev/migrie/s/1032-elevation-qol/doc/specs/%235000%20-%20Process%20Model%202.0/%231032%20-%20Elevation%20Quality%20of%20Life%20Improvements.md) ⇐


## Summary of the Pull Request

Despite my best efforts to mix elevation levels in a single Terminal window, it seems that there's no way to do that safely. With the dream of mixed elevation dead, this spec outlines a number of quality-of-life improvements we can make to the Terminal today. These should make using the terminal in elevated scenarios better, since we can't have M/E.

### Abstract

> For a long time, we've been researching adding support to the Windows Terminal
> for running both unelevated and elevated (admin) tabs side-by-side, in the same
> window. However, after much research, we've determined that there isn't a safe
> way to do this without opening the Terminal up as a potential
> escalation-of-privilege vector.
> 
> Instead, we'll be adding a number of features to the Terminal to improve the
> user experience of working in elevated scenarios. These improvements include:
> 
> * A visible indicator that the Terminal window is elevated ([#1939])
> * Configuring the Terminal to always run elevated ([#632])
> * Configuring a specific profile to always open elevated ([#632])
> * Allowing new tabs, panes to be opened elevated directly from an unelevated
>   window
> * Dynamic profile appearance that changes depending on if the Terminal is
>   elevated or not. ([#1939], [#8311])


## PR Checklist
* [x] Specs: #1032, #632
* [x] References: #5000, #4472, #2227, #7240, #8135, #8311
* [x] I work here

## Detailed Description of the Pull Request / Additional comments
_\*<sup>\*</sup><sub>\*</sub> read the spec  <sub>\*</sub><sup>\*</sup>\*_

### Why are these two separate documents?

I felt that the spec that is currently in review in #7240 and this doc should remain separate, yet closely related documents. #7240 is more about showing how this large set of problems discussed in #5000 can all be solved technically, and how those solutions can be used together. It establishes that none of the proposed solutions for components of #5000 will preclude the possibility of other components being solved. What it does _not_ do however is drill too deeply on the user experience that will be built on top of those architectural changes. 

This doc on the other hand focuses more closely on a pair of scenarios, and establishes how those scenarios will work technically, and how they'll be exposed to the user.
@androiddevnotes
Copy link

If someone needs the commands to create a new tab (and not open a new window) from a context menu item are:
(if you are already in the directory):
wt -w 0 nt
(and if you click on the directory):
wt -w 0 nt -d %1
You can add these commands in the respective registry of each item (or in a new one)

this really works it open a new tab, the problem is the directory was reset,.. hoping that I open a new tab, it will be at the same directory in my working project.

Try this:

wt -w 0 nt -d .

@lfr
Copy link

lfr commented Aug 30, 2021

And what would the commands be to open a new tab from within the terminal itself?

@zadjii-msft
Copy link
Member

wt -w 0 nt

wt-w-0

@lfr
Copy link

lfr commented Aug 30, 2021

@zadjii-msft thanks, but it doesn't seem to work from bash (Terminal Preview) 🤷‍♂️

@zadjii-msft
Copy link
Member

Ah, from WSL you'll need:

cmd.exe /c "wt.exe" -w 0 nt

Execution aliases do not work in WSL distributions. If you want to use wt.exe from a WSL command line, you can spawn it from CMD directly by running cmd.exe. The /c option tells CMD to terminate after running.

Also, you can read this in the docs

@hardeepparmar
Copy link

wt -w 0 nt

wt-w-0

But this works only from with in cmd tab window.. This does not work if you issue this command from say within powershell tabbed window.

@zadjii-msft
Copy link
Member

But this works only from with in cmd tab window.. This does not work if you issue this command from say within powershell tabbed window.

wt-w-0--powershell

🤔

@DJackman123
Copy link
Contributor

Beat me to the punch. Yes, it does work in a PowerShell tab. However, it does not work in a Windows Terminal window running as administrator (see #9628).

@hardeepparmar
Copy link

Beat me to the punch. Yes, it does work in a PowerShell tab. However, it does not work in a Windows Terminal window running as administrator (see #9628).

Yes indeed i am running Windows terminal as Administrator and I see this issue...However as you said, if I do not run at as administrator, it works just as expected. Thanks for confirming and making it more explicit and clear.

@MetaMmodern
Copy link

MetaMmodern commented Feb 12, 2022

For those who are kinda new to this: here is how you can do it the easy way.(Works for me in Windows 10 Pro with Windows Terminal(not Preview))

  1. Open Windows Terminal.
  2. Open Settings.
  3. Checkout this section in the startup menu.
    image
  4. Select as I did.
  5. Test by clicking "Open in Windows Terminal" elsewhere.
    Thanks Microsoft for adding this to GUI)

@LawranceFung
Copy link

For those who are kinda new to this: here is how you can do it the easy way.

1. Open Windows Terminal.

2. Open Settings.

3. Checkout this section in the startup menu.
   ![image](https://user-images.githubusercontent.com/42899786/153727389-56f004b6-cd7b-4b35-9531-ef2227e28638.png)

4. Select as I did.

5. Test by clicking "Open in Windows Terminal" elsewhere.
   Thanks Microsoft for adding this to GUI)

Neither "Attach to the most recently used window" nor "Attach to the most recently used window on this desktop" work for me on Windows 11. I am not using the Preview version of Windows Terminal. Any idea what's up?

@MetaMmodern
Copy link

For those who are kinda new to this: here is how you can do it the easy way.

1. Open Windows Terminal.

2. Open Settings.

3. Checkout this section in the startup menu.
   ![image](https://user-images.githubusercontent.com/42899786/153727389-56f004b6-cd7b-4b35-9531-ef2227e28638.png)

4. Select as I did.

5. Test by clicking "Open in Windows Terminal" elsewhere.
   Thanks Microsoft for adding this to GUI)

Neither "Attach to the most recently used window" nor "Attach to the most recently used window on this desktop" work for me on Windows 11. I am not using the Preview version of Windows Terminal. Any idea what's up?

Sorry, buddy, no idea. Try checking the above comments (like modifying the registry). I'll update my prev comment, cuz I'm on windows 10.

@LawranceFung
Copy link

Are there plans to launch a new tab in an existing window, but to choose the window based on MRU order?

@zadjii-msft
Copy link
Member

choose the window based on MRU order?

that's... already how it's supposed to work?
mru-wt--w-0

@DJackman123

This comment was marked as off-topic.

@zadjii-msft

This comment was marked as off-topic.

@LawranceFung
Copy link

choose the window based on MRU order?

that's... already how it's supposed to work? mru-wt--w-0

That's not working for me when calling
wt.exe -w 0 nt
or
wt.exe -w 1 nt
via AutoHotkey when both AutoHotkey and both Windows Terminal windows are running as administrator. It always opens the new tab in the first wt window opened.

@DJackman123
Copy link
Contributor

Wondering if that is related to #9628. Add this information to that bug so when it's evaluated for 1.14 this scenario will be included in that evaluation.

@LawranceFung
Copy link

Yes, should be same issue as #9628 barring some strange behavior when called by AHK.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Commandline wt.exe's commandline arguments Area-Server Down in the muck of API call servicing, interprocess communication, eventing, etc. Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.