[PR #15280] [MERGED] Use a "virtual CWD" for each terminal window #30563

Open
opened 2026-01-31 09:41:34 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/15280
Author: @zadjii-msft
Created: 5/3/2023
Status: Merged
Merged: 5/12/2023
Merged by: @zadjii-msft

Base: mainHead: dev/migrie/b/5506-virtual-cwd


📝 Commits (8)

  • 816f8b2 dirty: stash a string as a "virtual" CWD, ala #5506
  • 03e6044 cleanup for review
  • 5c377d8 cleanup from review
  • eb97e9f Merge remote-tracking branch 'origin/main' into dev/migrie/b/5506-virtual-cwd
  • c01611d start writing tests
  • 51a8df7 huzzah tests pass
  • 8c797f8 OKAY it works now
  • d51e18d audit mode strikes again

📊 Changes

12 files changed (+138 additions, -23 deletions)

View changed files

📝 src/cascadia/Remoting/Peasant.idl (+1 -1)
📝 src/cascadia/TerminalApp/TerminalPage.cpp (+15 -17)
📝 src/cascadia/TerminalApp/TerminalPage.idl (+2 -0)
📝 src/cascadia/TerminalApp/TerminalWindow.cpp (+5 -1)
📝 src/cascadia/TerminalApp/TerminalWindow.h (+7 -1)
📝 src/cascadia/TerminalApp/TerminalWindow.idl (+1 -1)
📝 src/cascadia/WindowsTerminal/AppHost.cpp (+1 -1)
📝 src/cascadia/WindowsTerminal/WindowEmperor.cpp (+11 -1)
📝 src/types/inc/utils.hpp (+3 -0)
📝 src/types/ut_types/UtilsTests.cpp (+64 -0)
📝 src/types/utils.cpp (+24 -0)
📝 tools/bcz.cmd (+4 -0)

📄 Description

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 https://github.com/microsoft/terminal/issues/4637#issuecomment-1531979200

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/15280 **Author:** [@zadjii-msft](https://github.com/zadjii-msft) **Created:** 5/3/2023 **Status:** ✅ Merged **Merged:** 5/12/2023 **Merged by:** [@zadjii-msft](https://github.com/zadjii-msft) **Base:** `main` ← **Head:** `dev/migrie/b/5506-virtual-cwd` --- ### 📝 Commits (8) - [`816f8b2`](https://github.com/microsoft/terminal/commit/816f8b2026368a4af12476d4c7de946acb238a7e) dirty: stash a string as a "virtual" CWD, ala #5506 - [`03e6044`](https://github.com/microsoft/terminal/commit/03e60443e5dc8c1ac4ab34ee44552ff8cc278c57) cleanup for review - [`5c377d8`](https://github.com/microsoft/terminal/commit/5c377d82cdaaa4f0e2c90808cdfb65597331c9e0) cleanup from review - [`eb97e9f`](https://github.com/microsoft/terminal/commit/eb97e9f76a0369d070995276a18b53b9249e8e9c) Merge remote-tracking branch 'origin/main' into dev/migrie/b/5506-virtual-cwd - [`c01611d`](https://github.com/microsoft/terminal/commit/c01611d5556c18dfeaf7c94176d61ac1f4c91f3b) start writing tests - [`51a8df7`](https://github.com/microsoft/terminal/commit/51a8df706d2a8772d52b60a5ca6987ca8a3b6779) huzzah tests pass - [`8c797f8`](https://github.com/microsoft/terminal/commit/8c797f8a6d335e18afb1067f788888e133f890ab) OKAY it works now - [`d51e18d`](https://github.com/microsoft/terminal/commit/d51e18d3ae1e8257d6ed2148274ad1c22861f012) audit mode strikes again ### 📊 Changes **12 files changed** (+138 additions, -23 deletions) <details> <summary>View changed files</summary> 📝 `src/cascadia/Remoting/Peasant.idl` (+1 -1) 📝 `src/cascadia/TerminalApp/TerminalPage.cpp` (+15 -17) 📝 `src/cascadia/TerminalApp/TerminalPage.idl` (+2 -0) 📝 `src/cascadia/TerminalApp/TerminalWindow.cpp` (+5 -1) 📝 `src/cascadia/TerminalApp/TerminalWindow.h` (+7 -1) 📝 `src/cascadia/TerminalApp/TerminalWindow.idl` (+1 -1) 📝 `src/cascadia/WindowsTerminal/AppHost.cpp` (+1 -1) 📝 `src/cascadia/WindowsTerminal/WindowEmperor.cpp` (+11 -1) 📝 `src/types/inc/utils.hpp` (+3 -0) 📝 `src/types/ut_types/UtilsTests.cpp` (+64 -0) 📝 `src/types/utils.cpp` (+24 -0) 📝 `tools/bcz.cmd` (+4 -0) </details> ### 📄 Description 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 https://github.com/microsoft/terminal/issues/4637#issuecomment-1531979200 > **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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:41:34 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#30563