ashald / EnvFile

EnvFile 3.x is a plugin for JetBrains IDEs that allows you to set environment variables for your run configurations from one or multiple files.
MIT License
548 stars 129 forks source link

Add a "script" option, #92

Closed DanielWeigl closed 3 years ago

DanielWeigl commented 5 years ago

which runs the provided script/executable and uses its output as .env file.

E.g to get the current branch name into an environment varible to use it for per-branch configurations in the development environment.

DanielWeigl commented 5 years ago

@ashald hi did you have any chance to review this change or any plans on merging it / releasing a new version?

ashald commented 4 years ago

@DanielWeigl hi there! Sorry for a super late reply. I have limited spare time these days and don't get to update this plugin often. First of all, thanks for your contribution!

I think the idea behind your change is really powerful and it opens doors to injecting arbitrary values sourced from the runtime environment or even through interpretation of unsupported formats.

I did a little research on such an approach and found that same effect can be achieved with current capabilities of the plugin and existing IDE functionality. It doesn't work exactly as the change you propose, but the result and capabilities are the same.

1) I added a run configuration to execute a shell script like this one:

echo "FOO=$(date)" > dev.env
image

2) Next, I opened a run configuration that I'm actually interested in and added the above one into "Run Before"

image

Now, whenever I run my Python script:

import os

print("Date is: "+os.environ.get("FOO"))

I get an up to date output.

I'm not sure when exactly "Shell Script" run configuration was added and if "Run Before" is available on all of existing run configurations. That being said, the less code there is the better so I'm rather inclined on not merging this PR to keep the plugin simpler. Please let mw know if I'm missing something.

DanielWeigl commented 3 years ago

Hi, no problem - i know how sparse time can be.

Yes your solution, running a script that generates the env-file also sounds okay'ish and has the same effect as my approach. Im okay with a none-merge in this case