microsoft / terminal

The new Windows Terminal and the original Windows console host, all in the same place!
MIT License
95.27k stars 8.27k forks source link

Set environment variable `WT_FOLDER_PATH` to the folder path that contains `WindowsTerminal.exe` #16295

Closed daxgames closed 6 months ago

daxgames commented 11 months ago

Description of the new feature/enhancement

Set an environment variable WT_FOLDER_PATH to the folder path that contains WindowsTerminal.exe. This variable should be set when Windows Terminal launches before the profile is launched.

This would be useful for users that run Windows Terminal in portable mode so Windows terminal profiles can be configured with paths relative to the folder wher WIndows Terminal is installed as shown below:

image

The normal user profile is configured as shown below and works perfectly because the %CMDER_ROOT% env variable was set dynamically before launching Windows Terminal.

image

The above configuration does not work when launching as Administrator because the %CMDER_ROOT% env variable is not set globally on the system nor in the Administator's personal environment variables. it produces the error below:

image

For completeness sake the icon config being complained about in the error above is below:

image

Proposed technical implementation details (optional)

zadjii-msft commented 11 months ago

~This really falls under the same problem space as #13006 et al. We could add that, sure,~

Wait, no it doesn't. This is actually so simple. Set that variable for terminal itself. So that we can resolve things relative to ourself. brilliant.

I think we were already tracking this in #15379 but I'll motion to use this as the tracking thread instead, since this has a real good idea. Thanks!

daxgames commented 4 months ago

The implemented solution in https://github.com/microsoft/terminal/pull/16949:

  1. Is confusing.
    • Is it %WT_SETTINGS_DIR% or %WT_SETTINGS_PATH%
    • I THINK it is %WT_SETTINGS_DIR% because it seems to MOSTLY work.
    • Does not COMPLETELY solve this issue. See below.

New Config:

image

Launching the profile:

image

The paths exist because the shell is configured using "%WT_SETTINGS_DIR%\..\..\init.bat" and the tab icon is correctly read from "%WT_SETTINGS_DIR%......\icons\cmder_red.ico".

daxgames commented 4 months ago

Also why can't this just be a normal env variable like the below that are set in 1.20.x:

image

Like this:

image

DHowett commented 4 months ago

Image

It's WT_SETTINGS_DIR 😄 (It may not work in the commandline field - we need to investigate that. It should work in any other field in the settings that supports paths.)

daxgames commented 4 months ago

See my edited comment above.

DHowett commented 4 months ago

Thanks!

daxgames commented 4 months ago

Thanks for the quick response and the fix!

I looked at the PR and it went back and forth on %WT_SETTINGS_DIR% and %WT_SETTINGS_PATH%. After posting the issue I went to the Release Notes and saw the correct env var but it still throws the icon message. Other than that it all works!

My only other concern is wrapping the icon path with double quotes causes it to fail. Not sure if that would be an issue if the icon were in a path that contained spaces.