TIL Justfiles can also be Just Scripts
October 23, 2024
TIL that Justfiles can turn into Just Scripts by adding #!/usr/bin/env just --justfile to the top of the file and running chmod +x on the file.
From the docs:
By adding a shebang line to the top of a
justfileand making it executable,justcan be used as an interpreter for scripts: https://github.com/casey/just?tab=readme-ov-file#just-scripts
just.sh
#!/usr/bin/env just --justfile
@_default:
just --justfile just.sh --list
@lint *ARGS:
uv --quiet run --with pre-commit-uv pre-commit run {{ ARGS }} --all-filesAfter you run chmod +x just.sh, this file may be run using ./just.sh, and sub-commands everything just <subcommand> will just work.
Please note that --justfile just.sh is needed if you want your Just Script to be able to introspect or call itself.
Why?
More and more of my clients are using Justfiles, and occasionally, I want some other recipes that may belong outside the default workflows. These can also be reusable between projects for some of my other internal tooling, so it’s an excellent resource to learn about.
Originally posted on: https://micro.webology.dev/2024/10/23/til-justfiles-can.html