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

Reload environment variables by default; add setting to disable #14999

Merged
merged 11 commits into from
Mar 17, 2023
5 changes: 5 additions & 0 deletions doc/cascadia/profiles.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2164,6 +2164,11 @@
"description": "When set to true, the background image for the currently focused profile is expanded to encompass the entire window, beneath other panes.",
"type": "boolean"
},
"compatibility.reloadEnvironmentVariables": {
"default": true,
"description": "When set to true, when opening a new tab or pane it will get reloaded environment variables.",
"type": "boolean"
},
"initialCols": {
"default": 120,
"description": "The number of columns displayed in the window upon first load. If \"launchMode\" is set to \"maximized\" (or \"maximizedFocus\"), this property is ignored.",
Expand Down
11 changes: 11 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <LibraryResources.h>
#include <TerminalCore/ControlKeyStates.hpp>
#include <til/latch.h>
#include <til/env.h>

#include "../../types/inc/utils.hpp"
#include "ColorHelper.h"
Expand Down Expand Up @@ -1280,6 +1281,16 @@ namespace winrt::TerminalApp::implementation
auto guidWString = Utils::GuidToString(profile.Guid());

StringMap envMap{};
if (_settings.GlobalSettings().ReloadEnvironmentVariables())
{
til::env environment;
environment.regenerate();

for (const auto& [key, value] : environment.as_map())
{
envMap.Insert(key, value);
}
}
envMap.Insert(L"WT_PROFILE_ID", guidWString);
Copy link
Member

Choose a reason for hiding this comment

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

I love the simplicity of this, but I am a little bit concerned about what happens after we hand this environment block off.

We produce a new env block here, painstakingly inserting it into envMap... and then ConptyConnection uses EnvironmentVariableMapW to generate a new map based on the current process environment and inserts the contents of envMap from here into it.

In brief... what we will get is a hybrid of Terminal's spawning environment and the current environment. As well, we will probably end up parsing the entire env twice.

Should we move this down to ConptyConnection (worm the boolean down in through the valueset for all I mind, ha) and make sure we do not call UpdateEnvironmentMapW?

envMap.Insert(L"WSLENV", L"WT_PROFILE_ID");

Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ namespace Microsoft.Terminal.Settings.Model
INHERITABLE_SETTING(Boolean, ForceFullRepaintRendering);
INHERITABLE_SETTING(Boolean, SoftwareRendering);
INHERITABLE_SETTING(Boolean, UseBackgroundImageForWindow);
INHERITABLE_SETTING(Boolean, ReloadEnvironmentVariables);
INHERITABLE_SETTING(Boolean, ForceVTInput);
INHERITABLE_SETTING(Boolean, DebugFeaturesEnabled);
INHERITABLE_SETTING(Boolean, StartOnUserLogin);
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/MTSMSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Author(s):
X(bool, ForceFullRepaintRendering, "experimental.rendering.forceFullRepaint", false) \
X(bool, SoftwareRendering, "experimental.rendering.software", false) \
X(bool, UseBackgroundImageForWindow, "experimental.useBackgroundImageForWindow", false) \
X(bool, ReloadEnvironmentVariables, "compatibility.reloadEnvironmentVariables", true) \
X(bool, ForceVTInput, "experimental.input.forceVT", false) \
X(bool, TrimBlockSelection, "trimBlockSelection", true) \
X(bool, DetectURLs, "experimental.detectURLs", true) \
Expand Down