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

Variable substitution with environment - allow for fallback to default #92854

Open
dellagustin-sap opened this issue Mar 17, 2020 · 5 comments
Open
Assignees
Labels
feature-request Request for new features or functionality variable-resolving
Milestone

Comments

@dellagustin-sap
Copy link

When doing variable substitution with environment (at debugging launch, but could be useful for tasks too - ${env:Name}), I would like to provide a fallback (default) when the environment variable is not set.

As an example, see the variable substitution scheme for Docker Compose: https://docs.docker.com/compose/compose-file/#variable-substitution

  • ${VARIABLE:-default} evaluates to default if VARIABLE is unset or empty in the environment.
  • ${VARIABLE-default} evaluates to default only if VARIABLE is unset in the environment.

The syntax for VS Code could be ${env:Name:-default} and ${env:Name-default} with the same logic.

VS Code version 1.42.1

@isidorn isidorn assigned alexr00 and unassigned isidorn Mar 17, 2020
@alexr00 alexr00 added feature-request Request for new features or functionality variable-resolving labels Mar 18, 2020
@alexr00 alexr00 added this to the Backlog Candidates milestone Mar 18, 2020
@vscodebot
Copy link

vscodebot bot commented Mar 18, 2020

This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

@dellagustin-sap
Copy link
Author

dellagustin-sap commented Mar 24, 2020

Hooorray, 20 👍
We go to backlog
I wish I had the time to do the contribution myself (assuming I would be smart enough to carry it forward)

@vscodebot
Copy link

vscodebot bot commented Mar 24, 2020

🙂 This feature request received a sufficient number of community upvotes and we moved it to our backlog. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

@flying-sheep
Copy link

Any way to circumvent this for now? I want to do use XDG basedir spec and prepend something to XDG_DATA_DIRS.

To this end I need to retrieve the value of XDG_DATA_DIRS if it’s set and use a default when it isn’t set, which would look like this:

"env": {
    "XDG_DATA_DIRS": "${workspaceFolder}/something:${env:XDG_DATA_DIRS-/usr/local/share:/usr/share}"
}

There seems to be no way to currently do this in a launch configuration, and falling back to the empty string will break every GUI application launched with that env value set.

@alexr00
Copy link
Member

alexr00 commented Apr 27, 2020

Instead of using env you could write an extension that provides a command and use command input variables

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality variable-resolving
Projects
None yet
Development

No branches or pull requests

4 participants