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

Use a "virtual CWD" for each terminal window #15280

Merged
merged 8 commits into from
May 12, 2023

Conversation

zadjii-msft
Copy link
Member

Before process model v3, each Terminal window was running in its own process, each with its own CWD. This allowed startingDirectory: . to work relative to the terminal's own CWD. However, now all windows share the same process, so there can only be one CWD. That's not great - folks who right-click "open in terminal", then "Use parent process directory" are only ever going to be able to use the CWD of the first terminal opened.

This PR remedies this issue, with a theory we had for another issue. Essentially, we'll give each Terminal window a "virtual" CWD. The Terminal isn't actually in that CWD, the terminal is in system32. This also will prevent the Terminal from locking the directory it was originally opened in.

Many more notes on this topic in #4637 (comment)

Warning

Breaking change‼️

This will break a profile like

{
    "commandline": "media-test.exe",
    "name": "Use CWD for media-test",
    "startingDirectory": "."
},

if the user right-clicks "open in terminal", then attempts to open that profile. There's some theoretical work we could do in a follow up to fix this, but I'm inclined to say that relative paths for commandlines were already dangerous and should have been avoided.

  In the dirtiest way possible, this seems to work for most "start with this CWD" scenarios.
@microsoft-github-policy-service microsoft-github-policy-service bot added Issue-Bug It either shouldn't be doing this or needs an investigation. Area-Commandline wt.exe's commandline arguments Area-Remoting Communication layer between windows. Often for windowing behavior, quake mode, etc. Priority-1 A description (P1) Product-Terminal The new Windows Terminal. Severity-Blocking We won't ship a release like this! No-siree. labels May 3, 2023
src/cascadia/WindowsTerminal/WindowEmperor.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/TerminalWindow.h Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/TerminalPage.cpp Outdated Show resolved Hide resolved
@microsoft-github-policy-service microsoft-github-policy-service bot added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels May 11, 2023
// with `~` or `/`.
const bool looksLikeLinux =
resultPath.size() >= 1 &&
(resultPath[0] == L'~' || resultPath[0] == L'/');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI I wouldn't use gsl::at, because it's poorly integrated into MSVC. til::at would be sufficient IMO, but .at(0) would work just as well.

@DHowett
Copy link
Member

DHowett commented May 12, 2023

When you put stuff in Utils, you gotta make sure it passes audit!

@zadjii-msft zadjii-msft enabled auto-merge (squash) May 12, 2023 17:55
@zadjii-msft zadjii-msft merged commit 5c08a86 into main May 12, 2023
@zadjii-msft zadjii-msft deleted the dev/migrie/b/5506-virtual-cwd branch May 12, 2023 18:20
DHowett pushed a commit that referenced this pull request May 12, 2023
Before process model v3, each Terminal window was running in its own process, each with its own CWD. This allowed `startingDirectory: .` to work relative to the terminal's own CWD. However, now all windows share the same process, so there can only be one CWD. That's not great - folks who right-click "open in terminal", then "Use parent process directory" are only ever going to be able to use the CWD of the _first_ terminal opened.

This PR remedies this issue, with a theory we had for another issue. Essentially, we'll give each Terminal window a "virtual" CWD. The Terminal isn't actually in that CWD, the terminal is in `system32`. This also will prevent the Terminal from locking the directory it was originally opened in.

* Closes #5506
* There wasn't a 1.18 issue for "Use parent process directory is broken" yet, presumably selfhosters aren't using that feature
* Related to #14957

Many more notes on this topic in #4637 (comment)

> **Warning**
> ## Breaking change‼️

This will break a profile like

```json
{
    "commandline": "media-test.exe",
    "name": "Use CWD for media-test",
    "startingDirectory": "."
},
```

if the user right-clicks "open in terminal", then attempts to open that profile. There's some theoretical work we could do in a follow up to fix this, but I'm inclined to say that relative paths for `commandline`s were already dangerous and should have been avoided.

(cherry picked from commit 5c08a86)
Service-Card-Id: 89180224
Service-Version: 1.18
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-Remoting Communication layer between windows. Often for windowing behavior, quake mode, etc. Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal. Severity-Blocking We won't ship a release like this! No-siree. zBugBash-Consider
Projects
Development

Successfully merging this pull request may close these issues.

Terminal locks its starting directory; perhaps it shouldn't do that?
4 participants