Shell prelude
Users often have scripts they'd like to source, alias they'd like to define, or environment variables they'd like to set for all or most shells in a justfile.
One possible way of supporting this would be to define a snippet of shell code which should be prepended to all shell commands. This could be supported with a shell-prelude setting:
set shell-prelude := 'export FOO=bar;'
foo:
echo $FOO
When running the recipe foo, the line echo $FOO would actually run export FOO=bar; echo $FOO.
One annoying thing is that the shell prelude would be executed before every line of a recipe, so if it were slow, it would significantly slow down execution.
I agree that would be nice. I'd need a shorthand to call the various recipes I have, and an alias in a shell prelude would do wonder.
As of today, it seems there is no real other way to perform that than to hack away at the default shell invocation. Which brings to the following point: the documentation does not seem to document what the precise invocation of the default shell is.
Good point, I documented this in #2129.
How would this work, shell injection?
It would actually be pretty easy, just prepend the prelude to the command before executing it. So here:
set shell-prelude := 'export FOO=bar;'
foo:
echo $FOO
foo would actual execute export FOO=bar;echo $FOO.
foowould actual executeexport FOO=bar;echo $FOO.
I think newline should come after the prelude, in case someone tries to get exotic
I actually think it should be up to the user to include whatever terminating whitespace they want. If just automatically prepends some kind of whitespace, either a space or a newline, the user won't have a way to easily override it, in case they don't want it.
I think I understand how you intend it to be used. Cool then
I would like to have this prelude, that may differ dependending on the shell used.
I have a bunch of function that i would like to define to more readability in the output
In CI, I have something like:
And I do not really see the difference between the command git lfs install -f and its output Updated git hooks. Using the -x bash option does not make the log more readable.
I'd like to have some function always defined in every subshell (colorful echo_and_run function in CI)