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

Terminal env vars (WT_SESSION, etc) aren't set when set as the Default Terminal #13006

Open
StartAutomating opened this issue Apr 30, 2022 · 7 comments
Labels
Area-DefApp Issue-Task It's a feature request, but it doesn't really need a major design. Priority-2 A description (P2) Product-Terminal The new Windows Terminal.
Milestone

Comments

@StartAutomating
Copy link

Windows Terminal version

1.12.10983.0

Windows build number

10.0.22000.0

Other Software

No response

Steps to reproduce

Change settings to launch terminal instead of command shell.
Close instances of terminal
Run powershell/pwsh
Check $env:WT_PROFILE_ID
See that it is blank

Expected Behavior

$ENV:WT_PROFILE_ID should never be blank, because having a blank profile ID disables changing settings for that profile.

Actual Behavior

$ENV:WT_PROFILE_ID is not set when terminal is launched with pwsh/powershell, after changing system settings.

@StartAutomating StartAutomating added the Issue-Bug It either shouldn't be doing this or needs an investigation. label Apr 30, 2022
@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 Apr 30, 2022
@zadjii-msft zadjii-msft added Product-Terminal The new Windows Terminal. Area-DefApp labels Aug 1, 2022
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Aug 1, 2022
@zadjii-msft zadjii-msft added Priority-2 A description (P2) Needs-Discussion Something that requires a team discussion before we can proceed and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Aug 1, 2022
@zadjii-msft zadjii-msft added this to the Backlog milestone Aug 1, 2022
@zadjii-msft zadjii-msft removed the Needs-Discussion Something that requires a team discussion before we can proceed label Aug 15, 2022
@zadjii-msft zadjii-msft changed the title $ENV:WT_PROFILE_ID is not set when terminal is launched instead of command shell Terminal env vars (WT_SESSION, etc) aren't set when set as the Default Terminal Aug 15, 2022
@zadjii-msft zadjii-msft added Issue-Task It's a feature request, but it doesn't really need a major design. and removed Issue-Bug It either shouldn't be doing this or needs an investigation. labels Aug 15, 2022
@zadjii-msft
Copy link
Member

Notes:

That summarizes the issue at hand, and a proposed solution. We think this'll require some additional OS side changes (but it would be great if it didn't)

@chausner
Copy link
Contributor

The same seems to apply to environment variables defined in settings.json. I guess this is by design.

@tig
Copy link

tig commented Oct 20, 2023

+1 on this.

Do this:

  • Start.Run "pwsh"
  • Type $env:WT_SESSION

image

This breaks console apps (e.g. those built with Terminal.Gui) that are trying to determine if they are running in WT by checking for WT_SESSION.

This bug also applies when running console apps in the VS 2022 debugger because WT_SESSION is not set there either.

@BDisp
Copy link

BDisp commented Oct 20, 2023

The better way to check what terminal default is set is read Windows registry, see https://support.microsoft.com/en-us/windows/command-prompt-and-windows-powershell-for-windows-11-6453ce98-da91-476f-8651-5c14d5777c20.

@tig
Copy link

tig commented Oct 20, 2023

The better way to check what terminal default is set is read Windows registry, see https://support.microsoft.com/en-us/windows/command-prompt-and-windows-powershell-for-windows-11-6453ce98-da91-476f-8651-5c14d5777c20.

No, checking the registry only helps determine the default terminal. This does not help code determine what terminal it is running in. The WT team needs to fix this bug that's causing WT_SESSION to not be set.

@BDisp
Copy link

BDisp commented Oct 20, 2023

No, checking the registry only helps determine the default terminal. This does not help code determine what terminal it is running in. The WT team needs to fix this bug that's causing WT_SESSION to not be set.

I have one doubt here. And if you have ope your application with cmd and you also have conhost and Windows Terminal opened, how the WT_SESSION will inform you that you are running your application on cmd or Windows Terminal? If Windows Terminal is opened and running another different app, I think the WT_SESSION will be also available but does not meaning that it's running your application. If I'm wrong I beg sorry for that.

@BDisp
Copy link

BDisp commented Oct 20, 2023

Sorry about my confusion. Run Win+R->pwsh.exe $env:WT_SESSION return empty, but run Win+R->C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.18.2822.0_x64__8wekyb3d8bbwe\WindowsTerminal.exe return a GUID.
I see that both commands open the same executable files C:\Program Files\PowerShell\7\pwsh.exe and C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.18.2822.0_x64__8wekyb3d8bbwe\WindowsTerminal.exe for the current user.
Thus I think the GUID should return on both commands and some fix must be done. Thanks.

shaneharper added a commit to shaneharper/dotfiles that referenced this issue Oct 26, 2023
This commit deletes the is_Windows_Terminal funcref added in 6390072; The lambda's definition was incorrect, e.g. after starting "Command Prompt" from the Windows 11 Start Menu the lambda would return false even when Windows Terminal was being used. (See microsoft/terminal#13006. microsoft/terminal#6269 (comment) claims to have code to check whether a program is running in Windows Terminal or not.)

There may be some Windows terminal programs that only support 16 colors, but that's not relevant to me.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-DefApp Issue-Task It's a feature request, but it doesn't really need a major design. Priority-2 A description (P2) Product-Terminal The new Windows Terminal.
Projects
None yet
Development

No branches or pull requests

5 participants