Add environment property to the profiles in settings.json #9158

Closed
opened 2026-01-31 01:47:27 +00:00 by claunia · 10 comments
Owner

Originally created by @intractabilis on GitHub (Jun 20, 2020).

Following @DHowett suggestion in #6585.

Description of the new feature/enhancement

For tools like MinGW you need certain environment variables to be set that define their behavior. It would be convenient to have these settings in the profile.

I suggest to add a property to the profile description in settings.json to set environment variables. For example

{
    "environment" : {
        "PATH": "c:/doomsday/emergency_commands/bin;${env:PATH}",
        "EMRGENCY_LEVEL_HIGH": "1"
    }
}
Originally created by @intractabilis on GitHub (Jun 20, 2020). Following @DHowett suggestion in #6585. # Description of the new feature/enhancement For tools like MinGW you need certain environment variables to be set that define their behavior. It would be convenient to have these settings in the profile. I suggest to add a property to the profile description in `settings.json` to set environment variables. For example ```JSON { "environment" : { "PATH": "c:/doomsday/emergency_commands/bin;${env:PATH}", "EMRGENCY_LEVEL_HIGH": "1" } } ```
Author
Owner

@zadjii-msft commented on GitHub (Jun 23, 2020):

Yep, this seems like a good and reasonable feature request. We'll need to make sure that the ${env:PATH} syntax is well-defined. I think we're already doing some sort of env var string replacing, so we could probably just re-use that.

@zadjii-msft commented on GitHub (Jun 23, 2020): Yep, this seems like a good and reasonable feature request. We'll need to make sure that the `${env:PATH}` syntax is well-defined. I think we're already doing some sort of env var string replacing, so we could probably just re-use that.
Author
Owner

@mle-ii commented on GitHub (Aug 14, 2020):

Glad to see this here... I just started using Windows Terminal and love it, and this was one item I was searching for in the docs on how to do. I would love to be able to set PATH here and not have to override it for all other consoles.

That said I could probably work around this by setting up a batch file to run when a console opens up. At least in my head this might be possible as I've used this for other things where I initialized the command line environment for specific tools.

@mle-ii commented on GitHub (Aug 14, 2020): Glad to see this here... I just started using Windows Terminal and love it, and this was one item I was searching for in the docs on how to do. I would love to be able to set PATH here and not have to override it for all other consoles. That said I could probably work around this by setting up a batch file to run when a console opens up. At least in my head this might be possible as I've used this for other things where I initialized the command line environment for specific tools.
Author
Owner

@CaiB commented on GitHub (Oct 1, 2020):

I got around this by making a .cmd file containing:

@echo off
cls
SET PATH=whatever
ssh me@myserver

(Just replace the ssh line with what you wanted to run)

And then in the config.json in the profile I have:

"commandline": "cmd /s /c C:/Path/To/MyFile.cmd"
@CaiB commented on GitHub (Oct 1, 2020): I got around this by making a `.cmd` file containing: ```cmd @echo off cls SET PATH=whatever ssh me@myserver ``` (Just replace the ssh line with what you wanted to run) And then in the `config.json` in the profile I have: ``` "commandline": "cmd /s /c C:/Path/To/MyFile.cmd" ```
Author
Owner

@KalleOlaviNiemitalo commented on GitHub (Oct 1, 2020):

Would "var": "" remove the environment variable or add it with an empty value? If the latter, then "var": null could remove the variable.

@KalleOlaviNiemitalo commented on GitHub (Oct 1, 2020): Would `"var": ""` remove the environment variable or add it with an empty value? If the latter, then `"var": null` could remove the variable.
Author
Owner

@rivy commented on GitHub (Oct 1, 2020):

If your needs are relatively simple, a commandline statement using cmd and a compound statement is a solution which works now, eg:

"commandline": "cmd.exe /k \"set ENV_VAR=foo && set PATH=%PATH%;bar/baz\"",
@rivy commented on GitHub (Oct 1, 2020): If your needs are relatively simple, a `commandline` statement using `cmd` and a compound statement is a solution which works now, eg: ``` "commandline": "cmd.exe /k \"set ENV_VAR=foo && set PATH=%PATH%;bar/baz\"", ```
Author
Owner

@KalleOlaviNiemitalo commented on GitHub (Oct 1, 2020):

https://github.com/microsoft/terminal/issues/2785 seems to ask for the same thing, except it does not mention any ${env:PATH} or equivalent syntax.

@KalleOlaviNiemitalo commented on GitHub (Oct 1, 2020): <https://github.com/microsoft/terminal/issues/2785> seems to ask for the same thing, except it does not mention any `${env:PATH}` or equivalent syntax.
Author
Owner

@dolpsdw commented on GitHub (Nov 17, 2020):

Terraform Example with Windows Terminal Variables
powershell
"commandline": "powershell.exe -NoExit $env:ENV_VAR='foo'; $env:Path += ';C:\\PORT\\terraform014;C:\\PORT\\apache-maven-3.6.3\\bin' ",

cmd
"commandline": "cmd.exe /k \"set ENV_VAR=foo && set PATH=%PATH%;C:\\PORT\\terraform014;C:\\PORT\\apache-maven-3.6.3\\bin\"",

@dolpsdw commented on GitHub (Nov 17, 2020): Terraform Example with Windows Terminal Variables powershell `"commandline": "powershell.exe -NoExit $env:ENV_VAR='foo'; $env:Path += ';C:\\PORT\\terraform014;C:\\PORT\\apache-maven-3.6.3\\bin' ",` cmd `"commandline": "cmd.exe /k \"set ENV_VAR=foo && set PATH=%PATH%;C:\\PORT\\terraform014;C:\\PORT\\apache-maven-3.6.3\\bin\"",`
Author
Owner

@KalleOlaviNiemitalo commented on GitHub (Nov 17, 2020):

If you have

{
    "environment" : {
        "HOMEDRIVE": "C:",
        "HOME": "${env:HOMEDRIVE}${env:HOMEPATH}",
        "HOMEPATH": "\\Users\\example"
    }
}

then should HOME use the original or new value of HOMEPATH? Should that depend on the lexical order of properties in the JSON object?

It might be easiest to implement this so that ${env:VAR} always means the original value, and the lexical order does not matter. If it becomes possible to define environment variables both globally and in each profile, then ${env:VAR} in a profile could refer to the value defined in the global environment object, and ${env:VAR} in the global environment could refer to the value received from Windows.

The syntax leaves room for adding ${new-env:VAR} with topological sorting later if needed.

@KalleOlaviNiemitalo commented on GitHub (Nov 17, 2020): If you have ```JSON { "environment" : { "HOMEDRIVE": "C:", "HOME": "${env:HOMEDRIVE}${env:HOMEPATH}", "HOMEPATH": "\\Users\\example" } } ``` then should HOME use the original or new value of HOMEPATH? Should that depend on the lexical order of properties in the JSON object? It might be easiest to implement this so that `${env:VAR}` always means the original value, and the lexical order does not matter. If it becomes possible to define environment variables both globally and in each profile, then `${env:VAR}` in a profile could refer to the value defined in the global `environment` object, and `${env:VAR}` in the global `environment` could refer to the value received from Windows. The syntax leaves room for adding `${new-env:VAR}` with topological sorting later if needed.
Author
Owner

@zadjii-msft commented on GitHub (Nov 23, 2020):

Oh my goodness, this is a dupe of #2785, isn't it. I'll move some of the relevant discussion over to that thread. Thanks for the help triaging @KalleOlaviNiemitalo!

/dup #2785

@zadjii-msft commented on GitHub (Nov 23, 2020): Oh my goodness, this _is_ a dupe of #2785, isn't it. I'll move some of the relevant discussion over to that thread. Thanks for the help triaging @KalleOlaviNiemitalo! /dup #2785
Author
Owner

@ghost commented on GitHub (Nov 23, 2020):

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@ghost commented on GitHub (Nov 23, 2020): Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#9158