Put repeatable project commands in a Justfile
Create a Justfile with a parameterized greeting and a test recipe, then run it from a project subdirectory.
how-to3 steps
Updated
in short
Store repeatable commands as named recipes in a justfile. Pass recipe arguments on the command line and use --list to discover available commands.
Use the small fixture below to check the workflow before applying it to your own project.
Tools used
Before you start
- A Bash or Zsh terminal on Linux or macOS
- The listed tools installed and available on PATH
Steps
Step 1: Create the recipes
The @ prefix hides the command itself while retaining its output.
shtrmn_guide_dir="$(mktemp -d)" cd "$trmn_guide_dir" cat > justfile <<'EOF' greet name="developer": @printf 'Hello, %s!\n' '{{name}}' test: @printf 'tests passed\n' EOFStep 2: Discover and run recipes
Use a simple name for this example; template substitution is not a general shell-escaping mechanism.
shjust --list just greet Ada just testStep 3: Run from a subdirectory
just searches upward for a justfile and runs these recipes from its directory.
shmkdir src cd src just greet AdaoutputHello, Ada!
Further reading
[Just manual](https://just.systems/man/en/)
FAQ
- Does just rebuild only changed files?
- No. This example uses just as a command runner. Use a build system when you need file dependency tracking.
- Can I safely substitute arbitrary user input?
- Do not interpolate untrusted text into recipe shell commands. Quoting and argument handling need separate consideration.