casey / just

🤖 Just a command runner
https://just.systems
Creative Commons Zero v1.0 Universal
20.6k stars 454 forks source link

Unexport environment variables per recipe using attribute #2409

Open W1M0R opened 23 hours ago

W1M0R commented 23 hours ago

Currently, environment variables can be unexported at the justfile level, using unexport. This will unexport the environment variable for all recipes:

unexport GIT_EXTERNAL_DIFF
unexport GIT_PAGER

# only this recipe should not have GIT_EXTERNAL_DIFF and GIT_PAGER exported
diff-delta:
  git diff | delta --line-numbers

# and this recipe should respect the parent shell's GIT_EXTERNAL_DIFF and GIT_PAGER, but won't due to the unexport statements
diff-default:
  git diff

In some cases it is helpful to unexport (in a cross-platform way) an environment variable (or a list of environment variables) for only a specific recipe. One workaround is to use submodules, e.g. justfile-git-defaults.just and justfile-git-overrides.just, but this feels cumbersome.

Ideally, it would be nice to be able to unexport using an attribute:

[unexport("GIT_EXTERNAL_DIFF", "GIT_PAGER")]
diff-delta:
  git diff | delta --line-numbers

diff-default:
  git diff

Related:

  1. https://github.com/casey/just/issues/2408
neunenak commented 6 hours ago

Seems to me that this issue should be combined with #2408 - the actual desired feature is a way to scope anything one can currently do with just variables to a single recipe (or maybe a group of recipes?), whether that's exporting, unexporting, etc.