Way to make a re-usable recipe code block? #1707
-
Is there a way to define a re-usable code block to be used in multiple recipes from within the Justfile? That would be nice to reduce the boiler plate of some just recipes that share common script code, but this common code can't be relegated to a subshell or called separately as another dependency. I found I can use a multiline just string, and then source it as a file redirect from each recipe, something like:
I could also source an external file for boilerplate bits, but would rather not do that. I could use triple backticks for multiline command evaluation instead possibly, but that context gets the default Justfile shell which differs from the shell I'd like it to have, and it's more complicated than necessary for what I'd like to do. Ideally, I could define a "just block" of code, and place it anywhere in the justfile for a direct substitution, like:
I don't think that exists? Thanks for any feedback. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
For those examples you could use
Does this work for your case? |
Beta Was this translation helpful? Give feedback.
-
Probably not it's intended use but [script('cat')] can also be used. set unstable
[private]
[script('cat')]
func_lib:
say_hello() {
echo "Hello $1"
}
[script]
foo:
source <(just func_lib)
say_hello 'foo'
[script]
bar:
source <(just func_lib)
say_hello 'bar' |
Beta Was this translation helpful? Give feedback.
For those examples you could use
set positional-arguments
-Does this work for your case?