Writing Justfiles
It fully documents the Justfile syntax and system.
<h1 align=center><code>just</code></h1>
is a handy way to save and run project-specific commands.
This readme is also available as a
book. The
book reflects the latest release, whereas the
readme on GitHub
reflects latest master.
Commands, called recipes, are stored in a file called
with syntax
inspired by
:
You can then run them with
:
console
$ just test-all
cc *.c -o main
./test --all
Yay, all your tests passed!
has a ton of useful features, and many improvements over
:
- is a command runner, not a build system, so it avoids much of
's complexity and idiosyncrasies.
No need for recipes!
- Linux, MacOS, Windows, and other reasonable unices are supported with no
additional dependencies. (Although if your system doesn't have an ,
you'll need to choose a different shell.)
- Errors are specific and informative, and syntax errors are reported along
with their source context.
- Recipes can accept command line arguments.
- Wherever possible, errors are resolved statically. Unknown recipes and
circular dependencies are reported before anything runs.
- loads files, making it easy to populate
environment variables.
- Recipes can be listed from the command line.
- Command line completion scripts are
available for most popular shells.
- Recipes can be written in
arbitrary languages, like Python or NodeJS.
- can be invoked from any subdirectory, not just the directory that
contains the .
- And much more!
If you need help with
please feel free to open an issue or ping me on
Discord. Feature requests and bug reports are
always welcome!
Quick Start
See the installation section for how to install
on your computer. Try
running
to make sure that it's installed correctly.
For an overview of the syntax, check out
this cheatsheet.
Once
is installed and working, create a file named
in the
root of your project with the following contents:
just
recipe-name:
echo 'This is a recipe!'
# this is a comment
another-recipe:
@echo 'This is another recipe.'
When you invoke
it looks for file
in the current directory
and upwards, so you can invoke it from any subdirectory of your project.
The search for a
is case insensitive, so any case, like
,
, or
, will work.
will also look for files with the
name
, in case you'd like to hide a
.
Running
with no arguments runs the first recipe in the
:
console
$ just
echo 'This is a recipe!'
This is a recipe!
One or more arguments specify the recipe(s) to run:
console
$ just another-recipe
This is another recipe.
prints each command to standard error before running it, which is why
was printed. This is suppressed for lines starting
with
, which is why
echo 'This is another recipe.'
was not printed.
Recipes stop running if a command fails. Here
will only run if
succeeds:
just
publish:
cargo test
# tests passed, time to publish!
cargo publish
Recipes can depend on other recipes. Here the
recipe depends on the
recipe, so
will run before
:
just
build:
cc main.c foo.c bar.c -o main
test: build
./test
sloc:
@echo "`wc -l *.c` lines of code"
console
$ just test
cc main.c foo.c bar.c -o main
./test
testing… all tests passed!
Recipes without dependencies will run in the order they're given on the command
line:
console
$ just build sloc
cc main.c foo.c bar.c -o main
1337 lines of code
Dependencies will always run first, even if they are passed after a recipe that
depends on them:
console
$ just test build
cc main.c foo.c bar.c -o main
./test
testing… all tests passed!
Recipes may depend on recipes in submodules:
Examples
A variety of
s can be found in the
examples directory and on
GitHub.
Features
The Default Recipe
When
is invoked without a recipe, it runs the recipe with the
attribute, or the first recipe in the
if no recipe has
the
attribute.
This recipe might be the most frequently run command in the project, like
running the tests:
You can also use dependencies to run multiple recipes by default:
just
default: lint build test
build:
echo Building…
test:
echo Testing…
lint:
echo Linting…
If no recipe makes sense as the default recipe, you can add a recipe to the
beginning of your
that lists the available recipes:
Listing Available Recipes
Recipes can be listed in alphabetical order with
:
console
$ just --list
Available recipes:
build
test
deploy
lint
Recipes in
submodules can be listed with
,
where
is a space- or
-separated module path:
$ cat justfile
mod foo
$ cat foo.just
mod bar
$ cat bar.just
baz:
$ just --list foo bar
Available recipes:
baz
$ just --list foo::bar
Available recipes:
baz
console
$ just --summary
build test deploy lint
Pass
to print recipes in the order they appear in the
:
just
test:
echo 'Testing!'
build:
echo 'Building!'
console
$ just --list --unsorted
Available recipes:
test
build
console
$ just --summary --unsorted
test build
If you'd like
to default to listing the recipes in the
, you
can use this as your default recipe:
Note that you may need to add
--justfile {{justfile()}}
to the line above.
Without it, if you executed
just -f /some/distant/justfile -d .
or
just -f ./non-standard-justfile
, the plain
inside the recipe
would not necessarily use the file you provided. It would try to find a
justfile in your current path, maybe even resulting in a
error.
The heading text can be customized with
:
console
$ just --list --list-heading $'Cool stuff…\n'
Cool stuff…
test
build
And the indentation can be customized with
:
console
$ just --list --list-prefix ····
Available recipes:
····test
····build
The argument to
replaces both the heading and the newline
following it, so it should contain a newline if non-empty. It works this way so
you can suppress the heading line entirely by passing the empty string:
console
$ just --list --list-heading ''
test
build
Invoking Multiple Recipes
Multiple recipes may be invoked on the command line at once:
just
build:
make web
serve:
python3 -m http.server -d out 8000
console
$ just build serve
make web
python3 -m http.server -d out 8000
Keep in mind that recipes with parameters will swallow arguments, even if they
match the names of other recipes:
just
build project:
make {{project}}
serve:
python3 -m http.server -d out 8000
console
$ just build serve
make: *** No rule to make target `serve'. Stop.
The
flag can be used to restrict command-line invocations to a single
recipe:
console
$ just --one build serve
error: Expected 1 command-line recipe invocation but found 2.
Working Directory
By default, recipes run with the working directory set to the directory that
contains the
.
The
attribute can be used to make recipes run with the working
directory set to directory in which
was invoked.
just
@foo:
pwd
[no-cd]
@bar:
pwd
console
$ cd subdir
$ just foo
/
$ just bar
/subdir
You can override the working directory for all recipes with
set working-directory := '…'
:
just
set working-directory := 'bar'
@foo:
pwd
console
$ pwd
/home/bob
$ just foo
/home/bob/bar
You can override the working directory for a specific recipe with the
attribute<sup>1.38.0</sup>:
just
[working-directory: 'bar']
@foo:
pwd
console
$ pwd
/home/bob
$ just foo
/home/bob/bar
The argument to the
setting or
attribute may be absolute or relative. If it is relative it is interpreted
relative to the default working directory.
Aliases
Aliases allow recipes to be invoked on the command line with alternative names:
just
alias b := build
build:
echo 'Building!'
console
$ just b
echo 'Building!'
Building!
The target of an alias may be a recipe in a submodule:
justfile
mod foo
alias baz := foo::bar
Settings
Settings control interpretation and execution. Each setting may be specified at
most once, anywhere in the
.
For example:
just
set shell := ["zsh", "-cu"]
foo:
# this line will be run as `zsh -cu 'ls **/*.txt'`
ls **/*.txt
Table of Settings
| Name | Value | Default | Description |
|---|
| boolean | | Allow recipes appearing later in a to override earlier recipes with the same name. |
allow-duplicate-variables
| boolean | | Allow variables appearing later in a to override earlier variables with the same name. |
| string | - | Load a file with a custom name, if present. |
| boolean | | Load a file, if present. |
| boolean | | Override existing environment variables with values from the file. |
| string | - | Load a file from a custom path and error if not present. Overrides . |
| boolean | | Error if a file isn't found. |
| boolean | | Export all variables as environment variables. |
| boolean | | Search in parent directory if the first recipe on the command line is not found. |
| boolean | | Ignore recipe lines beginning with . |
| boolean | | Pass positional arguments. |
| boolean | | Disable echoing recipe lines before executing. |
| <sup>1.33.0</sup> | | | Set command used to invoke recipes with empty attribute. |
| | - | Set command used to invoke recipes and evaluate backticks. |
| string | - | Create temporary directories in instead of the system default temporary directory. |
| <sup>1.31.0</sup> | boolean | | Enable unstable features. |
| boolean | | Use PowerShell on Windows as default shell. (Deprecated. Use instead. |
| | - | Set the command used to invoke recipes and evaluate backticks. |
| <sup>1.33.0</sup> | string | - | Set the working directory for recipes and backticks, relative to the default working directory. |
Boolean settings can be written as:
Which is equivalent to:
Non-boolean settings can be set to both strings and
expressions.<sup>1.46.0</sup>
However, because settings affect the behavior of backticks and many functions,
those expressions may not contain backticks or function calls, directly or
transitively via reference.
Allow Duplicate Recipes
If
is set to
, defining multiple recipes with
the same name is not an error and the last definition is used. Defaults to
.
just
set allow-duplicate-recipes
@foo:
echo foo
@foo:
echo bar
Allow Duplicate Variables
If
allow-duplicate-variables
is set to
, defining multiple variables
with the same name is not an error and the last definition is used. Defaults to
.
just
set allow-duplicate-variables
a := "foo"
a := "bar"
@foo:
echo {{a}}
Dotenv Settings
If any of
,
,
,
,
or
are set,
will try to load environment variables
from a file.
If
is set,
will look for a file at the given path, which
may be absolute, or relative to the working directory.
The command-line option
, short form
, can be used to set or
override
at runtime.
If
is set
will look for a file at the given path,
relative to the working directory and each of its ancestors.
If
is not set, but
or
are
set, just will look for a file named
, relative to the working directory
and each of its ancestors.
and
are similar, but
is only
checked relative to the working directory, whereas
is checked
relative to the working directory and each of its ancestors.
It is not an error if an environment file is not found, unless
is set.
The loaded variables are environment variables, not
variables, and so
must be accessed using
in recipes and backticks.
If
is set, variables from the environment file will override
existing environment variables.
For example, if your
file contains:
console
# a comment, will be ignored
DATABASE_ADDRESS=localhost:6379
SERVER_PORT=1337
just
set dotenv-load
serve:
@echo "Starting server with database $DATABASE_ADDRESS on port $SERVER_PORT…"
./server --database $DATABASE_ADDRESS --port $SERVER_PORT
console
$ just serve
Starting server with database localhost:6379 on port 1337…
./server --database $DATABASE_ADDRESS --port $SERVER_PORT
Export
The
setting causes all
variables to be exported as environment
variables. Defaults to
.
just
set export
a := "hello"
@foo b:
echo $a
echo $b
console
$ just foo goodbye
hello
goodbye
Positional Arguments
If
is
, recipe arguments will be passed as
positional arguments to commands. For linewise recipes, argument
will be
the name of the recipe.
For example, running this recipe:
just
set positional-arguments
@foo bar:
echo $0
echo $1
Will produce the following output:
console
$ just foo hello
foo
hello
When using an
-compatible shell, such as
or
,
expands to
the positional arguments given to the recipe, starting from one. When used
within double quotes as
, arguments including whitespace will be passed
on as if they were double-quoted. That is,
is equivalent to
…
When there are no positional parameters,
and
expand to nothing
(i.e., they are removed).
This example recipe will print arguments one by one on separate lines:
just
set positional-arguments
@test *args='':
bash -c 'while (( "$#" )); do echo - $1; shift; done' -- "$@"
Running it with two arguments:
console
$ just test foo "bar baz"
- foo
- bar baz
Positional arguments may also be turned on on a per-recipe basis with the
attribute<sup>1.29.0</sup>:
just
[positional-arguments]
@foo bar:
echo $0
echo $1
Note that PowerShell does not handle positional arguments in the same way as
other shells, so turning on positional arguments will likely break recipes that
use PowerShell.
If using PowerShell 7.4 or better, the
flag will make
positional arguments work as expected:
just
set shell := ['pwsh.exe', '-CommandWithArgs']
set positional-arguments
print-args a b c:
Write-Output @($args[1..($args.Count - 1)])
Shell
The
setting controls the command used to invoke recipe lines and
backticks. Shebang recipes are unaffected. The default shell is
.
just
# use python3 to execute recipe lines and backticks
set shell := ["python3", "-c"]
# use print to capture result of evaluation
foos := `print("foo" * 4)`
foo:
print("Snake snake snake snake.")
print("{{foos}}")
passes the command to be executed as an argument. Many shells will need
an additional flag, often
, to make them evaluate the first argument.
Windows Shell
uses
on Windows by default. To use a different shell on Windows,
use
:
just
set windows-shell := ["powershell.exe", "-NoLogo", "-Command"]
hello:
Write-Host "Hello, world!"
See
powershell.just
for a justfile that uses PowerShell on all platforms.
Windows PowerShell
uses the legacy binary, and is no
longer recommended. See the setting above for a more flexible
way to control which shell is used on Windows.
uses
on Windows by default. To use
instead, set
to true.
just
set windows-powershell := true
hello:
Write-Host "Hello, world!"
Python 3
just
set shell := ["python3", "-c"]
Bash
just
set shell := ["bash", "-uc"]
Z Shell
just
set shell := ["zsh", "-uc"]
Fish
just
set shell := ["fish", "-c"]
Nushell
just
set shell := ["nu", "-c"]
If you want to change the default table mode to
:
just
set shell := ['nu', '-m', 'light', '-c']
Nushell was written in Rust, and has
cross-platform support for Windows / macOS and Linux.
Documentation Comments
Comments immediately preceding a recipe will appear in
:
just
# build stuff
build:
./bin/build
# test stuff
test:
./bin/test
console
$ just --list
Available recipes:
build # build stuff
test # test stuff
The
attribute can be used to set or suppress a recipe's doc comment:
just
# This comment won't appear
[doc('Build stuff')]
build:
./bin/build
# This one won't either
[doc]
test:
./bin/test
console
$ just --list
Available recipes:
build # Build stuff
test
Expressions and Substitutions
Various operators and function calls are supported in expressions, which may be
used in assignments, default recipe arguments, and inside recipe body
substitutions.
just
tmpdir := `mktemp -d`
version := "0.2.7"
tardir := tmpdir / "awesomesauce-" + version
tarball := tardir + ".tar.gz"
config := quote(config_dir() / ".project-config")
publish:
rm -f {{tarball}}
mkdir {{tardir}}
cp README.md *.c {{ config }} {{tardir}}
tar zcvf {{tarball}} {{tardir}}
scp {{tarball}} me@server.com:release/
rm -rf {{tarball}} {{tardir}}
Concatenation
The
operator returns the left-hand argument concatenated with the
right-hand argument:
Logical Operators
The logical operators
and
can be used to coalesce string
values<sup>1.37.0</sup>, similar to Python's
and
. These operators
consider the empty string
to be false, and all other strings to be true.
These operators are currently unstable.
The
operator returns the empty string if the left-hand argument is the
empty string, otherwise it returns the right-hand argument:
justfile
foo := '' && 'goodbye' # ''
bar := 'hello' && 'goodbye' # 'goodbye'
The
operator returns the left-hand argument if it is non-empty, otherwise
it returns the right-hand argument:
justfile
foo := '' || 'goodbye' # 'goodbye'
bar := 'hello' || 'goodbye' # 'hello'
Joining Paths
The
operator can be used to join two strings with a slash:
$ just --evaluate foo
a/b
Note that a
is added even if one is already present:
just
foo := "a/"
bar := foo / "b"
$ just --evaluate bar
a//b
Absolute paths can also be constructed<sup>1.5.0</sup>:
The
operator uses the
character, even on Windows. Thus, using the
operator should be avoided with paths that use universal naming convention
(UNC), i.e., those that start with
, since forward slashes are not
supported with UNC paths.
Escaping
To write a recipe containing
, use
:
just
braces:
echo 'I {{{{LOVE}} curly braces!'
(An unmatched
is ignored, so it doesn't need to be escaped.)
Another option is to put all the text you'd like to escape inside of an
interpolation:
just
braces:
echo '{{'I {{LOVE}} curly braces!'}}'
Yet another option is to use
:
just
braces:
echo 'I {{ "{{" }}LOVE}} curly braces!'
Strings
,
, and
quoted string literals are
supported. Unlike in recipe bodies,
interpolations are not supported
inside strings.
Double-quoted strings support escape sequences:
just
carriage-return := "\r"
double-quote := "\""
newline := "\n"
no-newline := "\
"
slash := "\\"
tab := "\t"
unicode-codepoint := "\u{1F916}"
console
$ just --evaluate
"arriage-return := "
double-quote := """
newline := "
"
no-newline := ""
slash := "\"
tab := " "
unicode-codepoint := "🤖"
The unicode character escape sequence
<sup>1.36.0</sup> accepts up to
six hex digits.
Strings may contain line breaks:
just
single := '
hello
'
double := "
goodbye
"
Single-quoted strings do not recognize escape sequences:
console
$ just --evaluate
escapes := "\t\n\r\"\\"
Indented versions of both single- and double-quoted strings, delimited by
triple single- or double-quotes, are supported. Indented string lines are
stripped of a leading line break, and leading whitespace common to all
non-blank lines:
just
# this string will evaluate to `foo\nbar\n`
x := '''
foo
bar
'''
# this string will evaluate to `abc\n wuv\nxyz\n`
y := """
abc
wuv
xyz
"""
Similar to unindented strings, indented double-quoted strings process escape
sequences, and indented single-quoted strings ignore escape sequences. Escape
sequence processing takes place after unindentation. The unindentation
algorithm does not take escape-sequence produced whitespace or newlines into
account.
Shell-expanded strings
Strings prefixed with
are shell expanded<sup>1.27.0</sup>:
justfile
foobar := x'~/$FOO/${BAR}'
| Value | Replacement |
|---|
| value of environment variable |
| value of environment variable |
| value of environment variable , or if is not set |
| Leading | path to current user's home directory |
| Leading | path to 's home directory |
This expansion is performed at compile time, so variables from
files and
exported
variables cannot be used. However, this allows shell expanded
strings to be used in places like settings and import paths, which cannot
depend on
variables and
files.
Format strings
Strings prefixed with
are format strings<sup>1.44.0</sup>:
justfile
name := "world"
message := f'Hello, {{name}}!'
Format strings may contain interpolations delimited with
that contain
expressions. Format strings evaluate to the concatenated string fragments and
evaluated expressions.
Use
to include a literal
in a format string:
justfile
foo := f'I {{{{LOVE} curly braces!'
Ignoring Errors
Normally, if a command returns a non-zero exit status, execution will stop. To
continue execution after a command, even if it fails, prefix the command with
:
just
foo:
-cat foo
echo 'Done!'
console
$ just foo
cat foo
cat: foo: No such file or directory
echo 'Done!'
Done!
Functions
provides many built-in functions for use in expressions, including
recipe body
substitutions, assignments, and default parameter values.
All functions ending in
can be abbreviated to
. So
can also be written as
. In addition,
invocation_directory_native()
can be abbreviated to
.
System Information
- — Instruction set architecture. Possible values are: ,
, , , , , ,
, , , , , , and
.
- <sup>1.15.0</sup> - Number of logical CPUs.
- — Operating system. Possible values are: , ,
, , , , , ,
, , , , and .
- — Operating system family; possible values are: and
.
For example:
just
system-info:
@echo "This is an {{arch()}} machine".
console
$ just system-info
This is an x86_64 machine
The
function can be used to create cross-platform
s
that work on various operating systems. For an example, see
cross-platform.just
file.
External Commands
-
<sup>1.27.0</sup> returns the standard output of shell script
with zero or more positional arguments
. The shell used to
interpret
is the same shell that is used to evaluate recipe lines,
and can be changed with
.
is passed as the first argument, so if the command is
,
the full command line, with the default shell command
and
and
will be:
'sh' '-cu' 'echo $@' 'echo $@' 'foo' 'bar'
This is so that
works as expected, and
refers to the first
argument.
does not include the first positional argument, which is
expected to be the name of the program being run.
just
# arguments can be variables or expressions
file := '/sys/class/power_supply/BAT0/status'
bat0stat := shell('cat $1', file)
# commands can be variables or expressions
command := 'wc -l'
output := shell(command + ' "$1"', 'main.c')
# arguments referenced by the shell command must be used
empty := shell('echo', 'foo')
full := shell('echo $1', 'foo')
error := shell('echo $1')
just
# Using python as the shell. Since `python -c` sets `sys.argv[0]` to `'-c'`,
# the first "real" positional argument will be `sys.argv[2]`.
set shell := ["python3", "-c"]
olleh := shell('import sys; print(sys.argv[2][::-1])', 'hello')
Environment Variables
- <sup>1.15.0</sup> — Retrieves the environment variable with name , aborting
if it is not present.
just
home_dir := env('HOME')
test:
echo "{{home_dir}}"
- <sup>1.15.0</sup> — Retrieves the environment variable with
name , returning if it is not present.
- — Deprecated alias for .
env_var_or_default(key, default)
— Deprecated alias for .
A default can be substituted for an empty environment variable value with the
operator, currently unstable:
just
set unstable
foo := env('FOO', '') || 'DEFAULT_VALUE'
Executables
-
<sup>1.39.0</sup> — Search directories in the
environment variable for the executable
and return its full path, or
halt with an error if no executable with
exists.
just
bash := require("bash")
@test:
echo "bash: '{{bash}}'"
-
<sup>1.39.0</sup> — Search directories in the
environment
variable for the executable
and return its full path, or the empty
string if no executable with
exists. Currently unstable.
just
set unstable
bosh := which("bosh")
@test:
echo "bosh: '{{bosh}}'"
Invocation Information
- - Returns the string if the current recipe is being
run as a dependency of another recipe, rather than being run directly,
otherwise returns the string .
Invocation Directory
- - Retrieves the absolute path to the current
directory when was invoked, before changed it (chdir'd) prior
to executing commands. On Windows, uses to
convert the invocation directory to a Cygwin-compatible -separated path.
Use
invocation_directory_native()
to return the verbatim invocation
directory on all platforms.
For example, to call
on files just under the "current directory"
(from the user/invoker's perspective), use the following rule:
just
rustfmt:
find {{invocation_directory()}} -name \*.rs -exec rustfmt {} \;
Alternatively, if your command needs to be run from the current directory, you
could use (e.g.):
just
build:
cd {{invocation_directory()}}; ./some_script_that_needs_to_be_run_from_here
invocation_directory_native()
- Retrieves the absolute path to the current
directory when was invoked, before changed it (chdir'd) prior
to executing commands.
Justfile and Justfile Directory
- - Retrieves the path of the current .
- - Retrieves the path of the parent directory of the
current .
For example, to run a command relative to the location of the current
:
just
script:
{{justfile_directory()}}/scripts/some_script
Source and Source Directory
- <sup>1.27.0</sup> - Retrieves the path of the current source file.
- <sup>1.27.0</sup> - Retrieves the path of the parent directory of the
current source file.
and
behave the same as
and
in the root
, but will return the path and
directory, respectively, of the current
or
source file when
called from within an import or submodule.
Just Executable
- - Absolute path to the executable.
For example:
just
executable:
@echo The executable is at: {{just_executable()}}
console
$ just
The executable is at: /bin/just
Just Process ID
- - Process ID of the executable.
For example:
just
pid:
@echo The process ID is: {{ just_pid() }}
console
$ just
The process ID is: 420
String Manipulation
- <sup>1.27.0</sup> Append to whitespace-separated
strings in .
append('/src', 'foo bar baz')
→ 'foo/src bar/src baz/src'
- <sup>1.27.0</sup> Prepend to
whitespace-separated strings in .
prepend('src/', 'foo bar baz')
→
'src/foo src/bar src/baz'
- <sup>1.27.0</sup> - Percent-encode characters in
except , matching the behavior of the
JavaScript function.
- - Replace all single quotes with and prepend and append
single quotes to . This is sufficient to escape special characters for
many shells, including most Bourne shell descendants.
- - Replace all occurrences of in to .
replace_regex(s, regex, replacement)
- Replace all occurrences of
in to . Regular expressions are provided by the
Rust crate. See the
syntax documentation for usage
examples. Capture groups are supported. The string uses
Replacement string syntax.
- - Remove leading and trailing whitespace from .
- - Remove trailing whitespace from .
trim_end_match(s, substring)
- Remove suffix of matching .
trim_end_matches(s, substring)
- Repeatedly remove suffixes of matching
.
- - Remove leading whitespace from .
trim_start_match(s, substring)
- Remove prefix of matching .
trim_start_matches(s, substring)
- Repeatedly remove prefixes of
matching .
Case Conversion
- <sup>1.7.0</sup> - Convert first character of to uppercase
and the rest to lowercase.
- <sup>1.7.0</sup> - Convert to .
- <sup>1.7.0</sup> - Convert to .
- - Convert to lowercase.
- <sup>1.7.0</sup> - Convert to .
- <sup>1.7.0</sup> - Convert to .
- <sup>1.7.0</sup> - Convert to .
- <sup>1.7.0</sup> - Convert to .
- <sup>1.7.0</sup> - Convert to .
- - Convert to uppercase.
Path Manipulation
Fallible
- - Absolute path to relative in the working
directory.
absolute_path("./bar.txt")
in directory is
.
- <sup>1.24.0</sup> - Canonicalize by resolving symlinks and removing
, , and extra s where possible.
- - Extension of .
extension("/foo/bar.txt")
is
.
- - File name of with any leading directory components
removed.
file_name("/foo/bar.txt")
is .
- - File name of without extension.
file_stem("/foo/bar.txt")
is .
- - Parent directory of .
parent_directory("/foo/bar.txt")
is .
- - without extension.
without_extension("/foo/bar.txt")
is .
These functions can fail, for example if a path does not have an extension,
which will halt execution.
Infallible
- - Simplify by removing extra path separators,
intermediate components, and where possible. is
, is , is .
- - This function uses on Unix and on Windows, which can
be lead to unwanted behavior. The operator, e.g., , which always
uses , should be considered as a replacement unless s are specifically
desired on Windows. Join path with path . is
. Accepts two or more arguments.
Filesystem Access
- - Returns if the path points at an existing entity
and otherwise. Traverses symbolic links, and returns if the
path is inaccessible or points to a broken symlink.
- <sup>1.39.0</sup> - Returns the content of file at as
string.
Error Reporting
- - Abort execution and report error to user.
UUID and Hash Generation
- <sup>1.25.0</sup> - Return BLAKE3 hash of as hexadecimal string.
- <sup>1.25.0</sup> - Return BLAKE3 hash of file at as hexadecimal
string.
- - Return the SHA-256 hash of as hexadecimal string.
- - Return SHA-256 hash of file at as hexadecimal
string.
- - Generate a random version 4 UUID.
Random
- <sup>1.27.0</sup> - Generate a string of randomly
selected characters from , which may not contain repeated
characters. For example, will generate a random
64-character lowercase hex string.
Datetime
- <sup>1.30.0</sup> - Return local time with .
- <sup>1.30.0</sup> - Return UTC time with .
The arguments to
and
are
-style format
strings, see the
library docs
for details.
Semantic Versions
semver_matches(version, requirement)
<sup>1.16.0</sup> - Check whether a
semantic , e.g., matches a
, e.g., , returning if so and
otherwise.
Style
-
<sup>1.37.0</sup> - Return a named terminal display attribute
escape sequence used by
. Unlike terminal display attribute escape
sequence constants, which contain standard colors and styles,
returns an escape sequence used by
itself, and can be used to make
recipe output match
's own output.
Recognized values for
are
, for echoed recipe lines,
, and
.
For example, to style an error message:
just
scary:
@echo '{{ style("error") }}OH NO{{ NORMAL }}'
User Directories<sup>1.23.0</sup>
These functions return paths to user-specific directories for things like
configuration, data, caches, executables, and the user's home directory.
On Unix, these functions follow the
XDG Base Directory Specification.
On MacOS and Windows, these functions return the system-specified user-specific
directories. For example,
returns
on
MacOS and
on Windows.
See the
crate for more
details.
- - The user-specific cache directory.
- - The user-specific configuration directory.
- - The local user-specific configuration directory.
- - The user-specific data directory.
- - The local user-specific data directory.
- - The user-specific executable directory.
- - The user's home directory.
If you would like to use XDG base directories on all platforms you can use the
function with the appropriate environment variable and fallback,
although note that the XDG specification requires ignoring non-absolute paths,
so for full compatibility with spec-compliant applications, you would need to
do:
just
xdg_config_dir := if env('XDG_CONFIG_HOME', '') =~ '^/' {
env('XDG_CONFIG_HOME')
} else {
home_directory() / '.config'
}
Constants
A number of constants are predefined:
| Name | Value | Value on Windows |
|---|
| <sup>1.27.0</sup> | | |
| <sup>1.27.0</sup> | | |
| <sup>1.27.0</sup> | | |
| <sup>1.41.0</sup> | | |
| <sup>1.41.0</sup> | | |
| <sup>1.37.0</sup> | | |
| <sup>1.37.0</sup> | | |
| <sup>1.37.0</sup> | | |
| <sup>1.37.0</sup> | | |
| <sup>1.37.0</sup> | | |
| <sup>1.37.0</sup> | | |
| <sup>1.37.0</sup> | | |
| <sup>1.37.0</sup> | | |
| <sup>1.37.0</sup> | | |
| <sup>1.37.0</sup> | | |
| <sup>1.37.0</sup> | | |
| <sup>1.37.0</sup> | | |
| <sup>1.37.0</sup> | | |
| <sup>1.37.0</sup> | | |
| <sup>1.37.0</sup> | | |
| <sup>1.37.0</sup> | | |
| <sup>1.37.0</sup> | | |
| <sup>1.37.0</sup> | | |
| <sup>1.37.0</sup> | | |
| <sup>1.37.0</sup> | | |
| <sup>1.37.0</sup> | | |
| <sup>1.37.0</sup> | | |
| <sup>1.37.0</sup> | | |
| <sup>1.37.0</sup> | | |
console
$ just foo
0123456789abcdef
Constants starting with
are
ANSI escape sequences.
clears the screen, similar to the
command. The rest are of the
form
, where
is an integer, and set terminal display attributes.
Terminal display attribute escape sequences can be combined, for example text
weight
, text style
, foreground color
, and
background color
. They should be followed by
, to reset the
terminal back to normal.
Escape sequences should be quoted, since
is treated as a special character
by some shells.
just
@foo:
echo '{{BOLD + STRIKETHROUGH + CYAN + BG_BLUE}}Hi!{{NORMAL}}'
Attributes
Recipes,
statements, and aliases may be annotated with attributes that
change their behavior.
| Name | Type | Description |
|---|
| <sup>1.46.0</sup> | recipe | Print help string for in usage messages. |
| <sup>1.46.0</sup> | recipe | Require values of argument to be passed as option. |
| <sup>1.46.0</sup> | recipe | Require values of argument to be passed as short option. |
[arg(ARG, value="VALUE")]
<sup>1.46.0</sup> | recipe | Makes option a flag which does not take a value. |
[arg(ARG, pattern="PATTERN")]
<sup>1.45.0</sup> | recipe | Require values of argument to match regular expression . |
| <sup>1.17.0</sup> | recipe | Require confirmation prior to executing recipe. |
| <sup>1.23.0</sup> | recipe | Require confirmation prior to executing recipe with a custom prompt. |
| <sup>1.43.0</sup> | recipe | Use recipe as module's default recipe. |
| <sup>1.27.0</sup> | module, recipe | Set recipe or module's documentation comment to . |
| <sup>1.32.0</sup> | recipe | Set shebang recipe script's file extension to . should include a period if one is desired. |
| <sup>1.27.0</sup> | module, recipe | Put recipe or module in in group . |
| <sup>1.8.0</sup> | recipe | Enable recipe on Linux. |
| <sup>1.8.0</sup> | recipe | Enable recipe on MacOS. |
| <sup>1.42.0</sup> | recipe | Attach to recipe. |
| <sup>1.9.0</sup> | recipe | Don't change directory before executing recipe. |
| <sup>1.7.0</sup> | recipe | Don't print an error message if recipe fails. |
| <sup>1.23.0</sup> | recipe | Override globally quiet recipes and always echo out the recipe. |
| <sup>1.38.0</sup> | recipe | Enable recipe on OpenBSD. |
| <sup>1.42.0</sup> | recipe | Run this recipe's dependencies in parallel. |
| <sup>1.29.0</sup> | recipe | Turn on positional arguments for this recipe. |
| <sup>1.10.0</sup> | alias, recipe | Make recipe, alias, or variable private. See Private Recipes. |
| <sup>1.33.0</sup> | recipe | Execute recipe as script. See script recipes for more details. |
| <sup>1.32.0</sup> | recipe | Execute recipe as a script interpreted by . See script recipes for more details. |
| <sup>1.8.0</sup> | recipe | Enable recipe on Unixes. (Includes MacOS). |
| <sup>1.8.0</sup> | recipe | Enable recipe on Windows. |
[working-directory(PATH)]
<sup>1.38.0</sup> | recipe | Set recipe working directory. may be relative or absolute. If relative, it is interpreted relative to the default working directory. |
A recipe can have multiple attributes, either on multiple lines:
just
[no-cd]
[private]
foo:
echo "foo"
Or separated by commas on a single line<sup>1.14.0</sup>:
just
[no-cd, private]
foo:
echo "foo"
Attributes with a single argument may be written with a colon:
Enabling and Disabling Recipes<sup>1.8.0</sup>
The
,
,
, and
attributes are
configuration attributes. By default, recipes are always enabled. A recipe with
one or more configuration attributes will only be enabled when one or more of
those configurations is active.
This can be used to write
s that behave differently depending on
which operating system they run on. The
recipe in this
will
compile and run
, using a different C compiler and using the correct
output binary name for that compiler depending on the operating system:
just
[unix]
run:
cc main.c
./a.out
[windows]
run:
cl main.c
main.exe
Disabling Changing Directory<sup>1.9.0</sup>
normally executes recipes with the current directory set to the
directory that contains the
. This can be disabled using the
attribute. This can be used to create recipes which use paths
relative to the invocation directory, or which operate on the current
directory.
For example, this
recipe:
just
[no-cd]
commit file:
git add {{file}}
git commit
Can be used with paths that are relative to the current directory, because
prevents
from changing the current directory when executing
.
Requiring Confirmation for Recipes<sup>1.17.0</sup>
normally executes all recipes unless there is an error. The
attribute allows recipes require confirmation in the terminal prior to running.
This can be overridden by passing
to
, which will automatically
confirm any recipes marked by this attribute.
Recipes dependent on a recipe that requires confirmation will not be run if the
relied upon recipe is not confirmed, as well as recipes passed after any recipe
that requires confirmation.
just
[confirm]
delete-all:
rm -rf *
Custom Confirmation Prompt<sup>1.23.0</sup>
The default confirmation prompt can be overridden with
:
just
[confirm("Are you sure you want to delete everything?")]
delete-everything:
rm -rf *
Groups
Recipes and modules may be annotated with one or more group names:
just
[group('lint')]
js-lint:
echo 'Running JS linter…'
[group('rust recipes')]
[group('lint')]
rust-lint:
echo 'Running Rust linter…'
[group('lint')]
cpp-lint:
echo 'Running C++ linter…'
# not in any group
email-everyone:
echo 'Sending mass email…'
Recipes are listed by group:
$ just --list
Available recipes:
email-everyone # not in any group
[lint]
cpp-lint
js-lint
rust-lint
[rust recipes]
rust-lint
prints recipes in their justfile order within each group:
$ just --list --unsorted
Available recipes:
(no group)
email-everyone # not in any group
[lint]
js-lint
rust-lint
cpp-lint
[rust recipes]
rust-lint
Groups can be listed with
:
$ just --groups
Recipe groups:
lint
rust recipes
Use
to print groups in their justfile order.
Command Evaluation Using Backticks
Backticks can be used to store the result of commands:
just
localhost := `dumpinterfaces | cut -d: -f2 | sed 's/\/.*//' | sed 's/ //g'`
serve:
./serve {{localhost}} 8080
Indented backticks, delimited by three backticks, are de-indented in the same
manner as indented strings:
just
# This backtick evaluates the command `echo foo\necho bar\n`, which produces the value `foo\nbar\n`.
stuff := ```
echo foo
echo bar
See the [Strings](#strings) section for details on unindenting.
Backticks may not start with `#!`. This syntax is reserved for a future
upgrade.
The [`shell(…)` function](#external-commands) provides a more general mechanism
to invoke external commands, including the ability to execute the contents of a
variable as a command, and to pass arguments to a command.
### Conditional Expressions
`if`/`else` expressions evaluate different branches depending on if two
expressions evaluate to the same value:
```just
foo := if "2" == "2" { "Good!" } else { "1984" }
bar:
@echo "{{foo}}"
It is also possible to test for inequality:
just
foo := if "hello" != "goodbye" { "xyz" } else { "abc" }
bar:
@echo {{foo}}
And match against regular expressions:
just
foo := if "hello" =~ 'hel+o' { "match" } else { "mismatch" }
bar:
@echo {{foo}}
Regular expressions are provided by the
regex crate, whose syntax is documented on
docs.rs. Since regular expressions
commonly use backslash escape sequences, consider using single-quoted string
literals, which will pass slashes to the regex parser unmolested.
Conditional expressions short-circuit, which means they only evaluate one of
their branches. This can be used to make sure that backtick expressions don't
run when they shouldn't.
just
foo := if env_var("RELEASE") == "true" { `get-something-from-release-database` } else { "dummy-value" }
Conditionals can be used inside of recipes:
just
bar foo:
echo {{ if foo == "bar" { "hello" } else { "goodbye" } }}
Multiple conditionals can be chained:
just
foo := if "hello" == "goodbye" {
"xyz"
} else if "a" == "a" {
"abc"
} else {
"123"
}
bar:
@echo {{foo}}
Stopping execution with error
Execution can be halted with the
function. For example:
just
foo := if "hello" == "goodbye" {
"xyz"
} else if "a" == "b" {
"abc"
} else {
error("123")
}
Which produce the following error when run:
error: Call to function `error` failed: 123
|
16 | error("123")
Setting Variables from the Command Line
Variables can be overridden from the command line.
just
os := "linux"
test: build
./test --test {{os}}
build:
./build {{os}}
console
$ just
./build linux
./test --test linux
Any number of arguments of the form
can be passed before recipes:
console
$ just os=plan9
./build plan9
./test --test plan9
console
$ just --set os bsd
./build bsd
./test --test bsd
Getting and Setting Environment Variables
Exporting Variables
Assignments prefixed with the
keyword will be exported to recipes as
environment variables:
just
export RUST_BACKTRACE := "1"
test:
# will print a stack trace if it crashes
cargo test
Parameters prefixed with a
will be exported as environment variables:
just
test $RUST_BACKTRACE="1":
# will print a stack trace if it crashes
cargo test
Exported variables and parameters are not exported to backticks in the same scope.
just
export WORLD := "world"
# This backtick will fail with "WORLD: unbound variable"
BAR := `echo hello $WORLD`
just
# Running `just a foo` will fail with "A: unbound variable"
a $A $B=`echo $A`:
echo $A $B
When
export is set, all
variables are exported as environment
variables.
Unexporting Environment Variables<sup>1.29.0</sup>
Environment variables can be unexported with the
:
just
unexport FOO
@foo:
echo $FOO
$ export FOO=bar
$ just foo
sh: FOO: unbound variable
Getting Environment Variables from the environment
Environment variables from the environment are passed automatically to the
recipes.
just
print_home_folder:
echo "HOME is: '${HOME}'"
console
$ just
HOME is '/home/myuser'
Setting Variables from Environment Variables
Environment variables can be propagated to
variables using the
function.
See
environment-variables.
Recipe Parameters
Recipes may have parameters. Here recipe
has a parameter called
:
just
build target:
@echo 'Building {{target}}…'
cd {{target}} && make
To pass arguments on the command line, put them after the recipe name:
console
$ just build my-awesome-project
Building my-awesome-project…
cd my-awesome-project && make
To pass arguments to a dependency, put the dependency in parentheses along with
the arguments:
just
default: (build "main")
build target:
@echo 'Building {{target}}…'
cd {{target}} && make
Variables can also be passed as arguments to dependencies:
just
target := "main"
_build version:
@echo 'Building {{version}}…'
cd {{version}} && make
build: (_build target)
A command's arguments can be passed to dependency by putting the dependency in
parentheses along with the arguments:
just
build target:
@echo "Building {{target}}…"
push target: (build target)
@echo 'Pushing {{target}}…'
Parameters may have default values:
just
default := 'all'
test target tests=default:
@echo 'Testing {{target}}:{{tests}}…'
./test --tests {{tests}} {{target}}
Parameters with default values may be omitted:
console
$ just test server
Testing server:all…
./test --tests all server
Or supplied:
console
$ just test server unit
Testing server:unit…
./test --tests unit server
Default values may be arbitrary expressions, but expressions containing the
,
,
, or
operators must be parenthesized:
just
arch := "wasm"
test triple=(arch + "-unknown-unknown") input=(arch / "input.dat"):
./test {{triple}}
The last parameter of a recipe may be variadic, indicated with either a
or
a
before the argument name:
just
backup +FILES:
scp {{FILES}} me@server.com:
Variadic parameters prefixed with
accept
one or more arguments and expand
to a string containing those arguments separated by spaces:
console
$ just backup FAQ.md GRAMMAR.md
scp FAQ.md GRAMMAR.md me@server.com:
FAQ.md 100% 1831 1.8KB/s 00:00
GRAMMAR.md 100% 1666 1.6KB/s 00:00
Variadic parameters prefixed with
accept
zero or more arguments and
expand to a string containing those arguments separated by spaces, or an empty
string if no arguments are present:
just
commit MESSAGE *FLAGS:
git commit {{FLAGS}} -m "{{MESSAGE}}"
Variadic parameters can be assigned default values. These are overridden by
arguments passed on the command line:
just
test +FLAGS='-q':
cargo test {{FLAGS}}
substitutions may need to be quoted if they contain spaces. For
example, if you have the following recipe:
just
search QUERY:
lynx https://www.google.com/?q={{QUERY}}
And you type:
console
$ just search "cat toupee"
will run the command
lynx https://www.google.com/?q=cat toupee
, which
will get parsed by
as
,
https://www.google.com/?q=cat
, and
, and not the intended
and
https://www.google.com/?q=cat toupee
.
You can fix this by adding quotes:
just
search QUERY:
lynx 'https://www.google.com/?q={{QUERY}}'
Parameters prefixed with a
will be exported as environment variables:
Parameters may be constrained to match regular expression patterns using the
[arg("name", pattern="pattern")]
attribute<sup>1.45.0</sup>:
just
[arg('n', pattern='\d+')]
double n:
echo $(({{n}} * 2))
A leading
and trailing
are added to the pattern, so it must match the
entire argument value.
You may constrain the pattern to a number of alternatives using the
operator:
just
[arg('flag', pattern='--help|--version')]
info flag:
just {{flag}}
Regular expressions are provided by the
Rust crate. See the
syntax documentation for usage
examples.
Usage information for a recipe may be printed with the
subcommand<sup>1.46.0</sup>:
console
$ just --usage foo
Usage: just foo [OPTIONS] bar
Arguments:
bar
Help strings may be added to arguments using the
attribute:
just
[arg("bar", help="hello")]
foo bar:
console
$ just --usage foo
Usage: just foo bar
Arguments:
bar hello
Recipe Flags and Options
Recipe parameters are positional by default.
just
@foo bar:
echo bar={{bar}}
The parameter
is positional:
console
$ just foo hello
bar=hello
The
<sup>1.46.0</sup> attribute can be used to make a
parameter a long option.
just
[arg("bar", long="bar")]
foo bar:
The parameter
is given with the
option:
console
$ just foo --bar hello
bar=hello
Options may also be passed with
syntax:
console
$ just foo --bar=hello
bar=hello
The value of
can be omitted, in which case the option defaults to the
name of the parameter:
just
[arg("bar", long)]
foo bar:
The
<sup>1.46.0</sup> attribute can be used to make a
parameter a short option.
just
[arg("bar", short="b")]
foo bar:
The parameter
is given with the
option:
console
$ just foo -b hello
bar=hello
If a parameter has both a long and short option, it may be passed using either.
Variadic
and
parameters cannot be options.
The
[arg(ARG, value=VALUE, …)]
<sup>1.46.0</sup> attribute can be used with
or
to make a parameter a flag which does not take a value.
just
[arg("bar", long="bar", value="hello")]
foo bar:
The parameter
is given with the
option, but does not take a
value, and instead takes the value given in the
attribute:
console
$ just foo --bar
bar=hello
This is useful for unconditionally requiring a flag like
on dangerous
commands.
A flag is optional if its parameter has a default:
just
[arg("bar", long="bar", value="hello")]
foo bar="goodbye":
Causing it to receive the default when not passed in the invocation:
Dependencies
Dependencies run before recipes that depend on them:
In a given invocation of
, a recipe with the same arguments will only run
once, regardless of how many times it appears in the command-line invocation,
or how many times it appears as a dependency:
just
a:
@echo A
b: a
@echo B
c: a
@echo C
$ just a a a a a
A
$ just b c
A
B
C
Multiple recipes may depend on a recipe that performs some kind of setup, and
when those recipes run, that setup will only be performed once:
just
build:
cc main.c
test-foo: build
./a.out --test foo
test-bar: build
./a.out --test bar
$ just test-foo test-bar
cc main.c
./a.out --test foo
./a.out --test bar
Recipes in a given run are only skipped when they receive the same arguments:
just
build:
cc main.c
test TEST: build
./a.out --test {{TEST}}
$ just test foo test bar
cc main.c
./a.out --test foo
./a.out --test bar
Running Recipes at the End of a Recipe
Normal dependencies of a recipes always run before a recipe starts. That is to
say, the dependee always runs before the depender. These dependencies are
called "prior dependencies".
A recipe can also have subsequent dependencies, which run immediately after the
recipe and are introduced with an
:
just
a:
echo 'A!'
b: a && c d
echo 'B!'
c:
echo 'C!'
d:
echo 'D!'
…running b prints:
console
$ just b
echo 'A!'
A!
echo 'B!'
B!
echo 'C!'
C!
echo 'D!'
D!
Running Recipes in the Middle of a Recipe
doesn't support running recipes in the middle of another recipe, but you
can call
recursively in the middle of a recipe. Given the following
:
just
a:
echo 'A!'
b: a
echo 'B start!'
just c
echo 'B end!'
c:
echo 'C!'
…running b prints:
console
$ just b
echo 'A!'
A!
echo 'B start!'
B start!
echo 'C!'
C!
echo 'B end!'
B end!
This has limitations, since recipe
is run with an entirely new invocation
of
: Assignments will be recalculated, dependencies might run twice, and
command line arguments will not be propagated to the child
process.
Shebang Recipes
Recipes that start with
are called shebang recipes, and are executed by
saving the recipe body to a file and running it. This lets you write recipes in
different languages:
just
polyglot: python js perl sh ruby nu
python:
#!/usr/bin/env python3
print('Hello from python!')
js:
#!/usr/bin/env node
console.log('Greetings from JavaScript!')
perl:
#!/usr/bin/env perl
print "Larry Wall says Hi!\n";
sh:
#!/usr/bin/env sh
hello='Yo'
echo "$hello from a shell script!"
nu:
#!/usr/bin/env nu
let hello = 'Hola'
echo $"($hello) from a nushell script!"
ruby:
#!/usr/bin/env ruby
puts "Hello from ruby!"
console
$ just polyglot
Hello from python!
Greetings from JavaScript!
Larry Wall says Hi!
Yo from a shell script!
Hola from a nushell script!
Hello from ruby!
On Unix-like operating systems, including Linux and MacOS, shebang recipes are
executed by saving the recipe body to a file in a temporary directory, marking
the file as executable, and executing it. The OS then parses the shebang line
into a command line and invokes it, including the path to the file. For
example, if a recipe starts with
, the final command that
the OS runs will be something like
/usr/bin/env bash /tmp/PATH_TO_SAVED_RECIPE_BODY
.
Shebang line splitting is operating system dependent. When passing a command
with arguments, you may need to tell
to split them explicitly by using
the
flag:
just
run:
#!/usr/bin/env -S bash -x
ls
Windows does not support shebang lines. On Windows,
splits the shebang
line into a command and arguments, saves the recipe body to a file, and invokes
the split command and arguments, adding the path to the saved recipe body as
the final argument. For example, on Windows, if a recipe starts with
,
the final command the OS runs will be something like
py C:\Temp\PATH_TO_SAVED_RECIPE_BODY
.
Script Recipes
Recipes with a
<sup>1.32.0</sup> attribute are run as
scripts interpreted by
. This avoids some of the issues with shebang
recipes, such as the use of
on Windows, the need to use
, inconsistencies in shebang line splitting across Unix OSs, and
requiring a temporary directory from which files can be executed.
Recipes with an empty
attribute are executed with the value of
set script-interpreter := […]
<sup>1.33.0</sup>, defaulting to
, and
not
the value of
.
The body of the recipe is evaluated, written to disk in the temporary
directory, and run by passing its path as an argument to
.
Script and Shebang Recipe Temporary Files
Both script and shebang recipes write the recipe body to a temporary file for
execution. Script recipes execute that file by passing it to a command, while
shebang recipes execute the file directly. Shebang recipe execution will fail
if the filesystem containing the temporary file is mounted with
or is
otherwise non-executable.
The directory that
writes temporary files to may be configured in a
number of ways, from highest to lowest precedence:
- Globally with the command-line option or the
environment variable<sup>1.41.0</sup>.
- On a per-module basis with the setting.
- Globally on Linux with the environment variable.
- Falling back to the directory returned by
std::env::temp_dir.
Python Recipes with
is an excellent cross-platform python
project manager, written in Rust.
Using the
attribute and
setting,
can
easily be configured to run Python recipes with
:
just
set unstable
set script-interpreter := ['uv', 'run', '--script']
[script]
hello:
print("Hello from Python!")
[script]
goodbye:
# /// script
# requires-python = ">=3.11"
# dependencies=["sh"]
# ///
import sh
print(sh.echo("Goodbye from Python!"), end='')
Of course, a shebang also works:
just
hello:
#!/usr/bin/env -S uv run --script
print("Hello from Python!")
Safer Bash Shebang Recipes
If you're writing a
shebang recipe, consider adding
:
just
foo:
#!/usr/bin/env bash
set -euxo pipefail
hello='Yo'
echo "$hello from Bash!"
It isn't strictly necessary, but
turns on a few useful
features that make
shebang recipes behave more like normal, linewise
recipe:
- makes exit if a command fails.
- makes exit if a variable is undefined.
- makes print each script line before it's run.
- makes exit if a command in a pipeline fails. This is
-specific, so isn't turned on in normal linewise recipes.
Together, these avoid a lot of shell scripting gotchas.
Shebang Recipe Execution on Windows
On Windows, shebang interpreter paths containing a
are translated from
Unix-style paths to Windows-style paths using
, a utility that ships
with
Cygwin.
For example, to execute this recipe on Windows:
just
echo:
#!/bin/sh
echo "Hello!"
The interpreter path
will be translated to a Windows-style path using
before being executed.
If the interpreter path does not contain a
it will be executed without
being translated. This is useful if
is not available, or you wish to
pass a Windows-style path to the interpreter.
Setting Variables in a Recipe
Recipe lines are interpreted by the shell, not
, so it's not possible to
set
variables in the middle of a recipe:
justfile
foo:
x := "hello" # This doesn't work!
echo {{x}}
It is possible to use shell variables, but there's another problem. Every
recipe line is run by a new shell instance, so variables set in one line won't
be set in the next:
just
foo:
x=hello && echo $x # This works!
y=bye
echo $y # This doesn't, `y` is undefined here!
The best way to work around this is to use a shebang recipe. Shebang recipe
bodies are extracted and run as scripts, so a single shell instance will run
the whole thing:
just
foo:
#!/usr/bin/env bash
set -euxo pipefail
x=hello
echo $x
Sharing Environment Variables Between Recipes
Each line of each recipe is executed by a fresh shell, so it is not possible to
share environment variables between recipes.
Using Python Virtual Environments
Some tools, like
Python's venv,
require loading environment variables in order to work, making them challenging
to use with
. As a workaround, you can execute the virtual environment
binaries directly:
just
venv:
[ -d foo ] || python3 -m venv foo
run: venv
./foo/bin/python3 main.py
Changing the Working Directory in a Recipe
Each recipe line is executed by a new shell, so if you change the working
directory on one line, it won't have an effect on later lines:
just
foo:
pwd # This `pwd` will print the same directory…
cd bar
pwd # …as this `pwd`!
There are a couple ways around this. One is to call
on the same line as
the command you want to run:
The other is to use a shebang recipe. Shebang recipe bodies are extracted and
run as scripts, so a single shell instance will run the whole thing, and thus a
on one line will affect later lines, just like a shell script:
just
foo:
#!/usr/bin/env bash
set -euxo pipefail
cd bar
pwd
Indentation
Recipe lines can be indented with spaces or tabs, but not a mix of both. All of
a recipe's lines must have the same type of indentation, but different recipes
in the same
may use different indentation.
Each recipe must be indented at least one level from the
but
after that may be further indented.
Here's a justfile with a recipe indented with spaces, represented as
, and
tabs, represented as
.
justfile
set windows-shell := ["pwsh", "-NoLogo", "-NoProfileLoadTime", "-Command"]
set ignore-comments
list-space directory:
··#!pwsh
··foreach ($item in $(Get-ChildItem {{directory}} )) {
····echo $item.Name
··}
··echo ""
# indentation nesting works even when newlines are escaped
list-tab directory:
→ @foreach ($item in $(Get-ChildItem {{directory}} )) { \
→ → echo $item.Name \
→ }
→ @echo ""
pwsh
PS > just list-space ~
Desktop
Documents
Downloads
PS > just list-tab ~
Desktop
Documents
Downloads
Multi-Line Constructs
Recipes without an initial shebang are evaluated and run line-by-line, which
means that multi-line constructs probably won't do what you want.
For example, with the following
:
justfile
conditional:
if true; then
echo 'True!'
fi
The extra leading whitespace before the second line of the
recipe
will produce a parse error:
console
$ just conditional
error: Recipe line has extra leading whitespace
|
3 | echo 'True!'
| ^^^^^^^^^^^^^^^^
To work around this, you can write conditionals on one line, escape newlines
with slashes, or add a shebang to your recipe. Some examples of multi-line
constructs are provided for reference.
statements
just
conditional:
if true; then echo 'True!'; fi
just
conditional:
if true; then \
echo 'True!'; \
fi
just
conditional:
#!/usr/bin/env sh
if true; then
echo 'True!'
fi
loops
just
for:
for file in `ls .`; do echo $file; done
just
for:
for file in `ls .`; do \
echo $file; \
done
just
for:
#!/usr/bin/env sh
for file in `ls .`; do
echo $file
done
loops
just
while:
while `server-is-dead`; do ping -c 1 server; done
just
while:
while `server-is-dead`; do \
ping -c 1 server; \
done
just
while:
#!/usr/bin/env sh
while `server-is-dead`; do
ping -c 1 server
done
Outside Recipe Bodies
Parenthesized expressions can span multiple lines:
just
abc := ('a' +
'b'
+ 'c')
abc2 := (
'a' +
'b' +
'c'
)
foo param=('foo'
+ 'bar'
):
echo {{param}}
bar: (foo
'Foo'
)
echo 'Bar!'
Lines ending with a backslash continue on to the next line as if the lines were
joined by whitespace<sup>1.15.0</sup>:
just
a := 'foo' + \
'bar'
foo param1 \
param2='foo' \
*varparam='': dep1 \
(dep2 'foo')
echo {{param1}} {{param2}} {{varparam}}
dep1: \
# this comment is not part of the recipe body
echo 'dep1'
dep2 \
param:
echo 'Dependency with parameter {{param}}'
Backslash line continuations can also be used in interpolations. The line
following the backslash must be indented.
just
recipe:
echo '{{ \
"This interpolation " + \
"has a lot of text." \
}}'
echo 'back to recipe body'
Command-line Options
supports a number of useful command-line options for listing, dumping,
and debugging recipes and variables:
console
$ just --list
Available recipes:
js
perl
polyglot
python
ruby
$ just --show perl
perl:
#!/usr/bin/env perl
print "Larry Wall says Hi!\n";
$ just --show polyglot
polyglot: python js perl sh ruby
Setting Command-line Options with Environment Variables
Some command-line options can be set with environment variables
For example, unstable features can be enabled either with the
flag:
Or by setting the
environment variable:
console
$ export JUST_UNSTABLE=1
$ just
Since environment variables are inherited by child processes, command-line
options set with environment variables are inherited by recursive invocations
of
, where as command line options set with arguments are not.
Consult
for which options can be set with environment variables.
Private Recipes
Recipes and aliases whose name starts with a
are omitted from
:
just
test: _test-helper
./bin/test
_test-helper:
./bin/super-secret-test-helper-stuff
console
$ just --list
Available recipes:
test
The
attribute<sup>1.10.0</sup> may also be used to hide recipes or
aliases without needing to change the name:
just
[private]
foo:
[private]
alias b := bar
bar:
console
$ just --list
Available recipes:
bar
This is useful for helper recipes which are only meant to be used as
dependencies of other recipes.
Quiet Recipes
A recipe name may be prefixed with
to invert the meaning of
before each
line:
just
@quiet:
echo hello
echo goodbye
@# all done!
Now only the lines starting with
will be echoed:
console
$ just quiet
hello
goodbye
# all done!
All recipes in a Justfile can be made quiet with
:
just
set quiet
foo:
echo "This is quiet"
@foo2:
echo "This is also quiet"
The
attribute overrides this setting:
just
set quiet
foo:
echo "This is quiet"
[no-quiet]
foo2:
echo "This is not quiet"
Shebang recipes are quiet by default:
just
foo:
#!/usr/bin/env bash
echo 'Foo!'
Adding
to a shebang recipe name makes
print the recipe before
executing it:
just
@bar:
#!/usr/bin/env bash
echo 'Bar!'
console
$ just bar
#!/usr/bin/env bash
echo 'Bar!'
Bar!
normally prints error messages when a recipe line fails. These error
messages can be suppressed using the
<sup>1.7.0</sup>
attribute. You may find this especially useful with a recipe that wraps a tool:
console
$ just git status
fatal: not a git repository (or any of the parent directories): .git
error: Recipe `git` failed on line 2 with exit code 128
Add the attribute to suppress the exit error message when the tool exits with a
non-zero code:
just
[no-exit-message]
git *args:
@git {{args}}
console
$ just git status
fatal: not a git repository (or any of the parent directories): .git
Selecting Recipes to Run With an Interactive Chooser
The
subcommand makes
invoke a chooser to select which recipes
to run. Choosers should read lines containing recipe names from standard input
and print one or more of those names separated by spaces to standard output.
Because there is currently no way to run a recipe that requires arguments with
, such recipes will not be given to the chooser. Private recipes and
aliases are also skipped.
The chooser can be overridden with the
flag. If
is not
given, then
first checks if
is set. If it isn't, then
the chooser defaults to
, a popular fuzzy finder.
Arguments can be included in the chooser, i.e.
.
The chooser is invoked in the same way as recipe lines. For example, if the
chooser is
, it will be invoked with
, and if the shell, or
the shell arguments are overridden, the chooser invocation will respect those
overrides.
If you'd like
to default to selecting recipes with a chooser, you can
use this as your default recipe:
Invoking s in Other Directories
If the first argument passed to
contains a
, then the following
occurs:
- The argument is split at the last .
- The part before the last is treated as a directory. will start
its search for the there, instead of in the current directory.
- The part after the last slash is treated as a normal argument, or ignored
if it is empty.
This may seem a little strange, but it's useful if you wish to run a command in
a
that is in a subdirectory.
For example, if you are in a directory which contains a subdirectory named
, which contains a
with the recipe
, which is also the
default recipe, the following are all equivalent:
console
$ (cd foo && just build)
$ just foo/build
$ just foo/
Additional recipes after the first are sought in the same
. For
example, the following are both equivalent:
console
$ just foo/a b
$ (cd foo && just a b)
And will both invoke recipes
and
in
.
Imports
One
can include the contents of another using
statements.
If you have the following
:
justfile
import 'foo/bar.just'
a: b
@echo A
And the following text in
:
will be included in
and recipe
will be defined:
The
path can be absolute or relative to the location of the justfile
containing it. A leading
in the import path is replaced with the current
users home directory.
Justfiles are insensitive to order, so included files can reference variables
and recipes defined after the
statement.
Imported files can themselves contain
s, which are processed
recursively.
and
allow-duplicate-variables
allow duplicate
recipes and variables, respectively, to override each other, instead of
producing an error.
Within a module, later definitions override earlier definitions:
just
set allow-duplicate-recipes
foo:
foo:
echo 'yes'
When
s are involved, things unfortunately get much more complicated and
hard to explain.
Shallower definitions always override deeper definitions, so recipes at the top
level will override recipes in imports, and recipes in an import will override
recipes in an import which itself imports those recipes.
When two duplicate definitions are imported and are at the same depth, the one
from the earlier import will override the one from the later import.
This is because
uses a stack when processing imports, pushing imports
onto the stack in source-order, and always processing the top of the stack
next, so earlier imports are actually handled later by the compiler.
This is definitely a bug, but since
has very strong backwards
compatibility guarantees and we take enormous pains not to break anyone's
, we have created issue #2540 to discuss whether or not we can
actually fix it.
Imports may be made optional by putting a
after the
keyword:
Importing the same source file multiple times is not an error<sup>1.37.0</sup>.
This allows importing multiple justfiles, for example
and
, which both import a third justfile containing shared recipes, for
example
, without the duplicate import of
being an error:
justfile
# justfile
import 'foo.just'
import 'bar.just'
justfile
# foo.just
import 'baz.just'
foo: baz
justfile
# bar.just
import 'baz.just'
bar: baz
Modules<sup>1.19.0</sup>
A
can declare modules using
statements.
statements were stabilized in
<sup>1.31.0</sup>. In earlier
versions, you'll need to use the
flag,
, or set the
environment variable to use them.
If you have the following
:
And the following text in
:
will be included in
as a submodule. Recipes, aliases, and
variables defined in one submodule cannot be used in another, and each module
uses its own settings.
Recipes in submodules can be invoked as subcommands:
Or with path syntax:
If a module is named
, just will search for the module file in
,
,
, and
. In the latter two cases,
the module file may have any capitalization.
Module statements may be of the form:
Which loads the module's source file from
, instead of from the usual
locations. A leading
in
is replaced with the current user's home
directory.
may point to the module source file itself, or to a directory
containing the module source file with the name
,
, or
. In the latter two cases, the module file may have any
capitalization.
Environment files are only loaded for the root justfile, and loaded environment
variables are available in submodules. Settings in submodules that affect
environment file loading are ignored.
Recipes in submodules without the
attribute run with the working
directory set to the directory containing the submodule source file.
and
always return the path to the root
justfile and the directory that contains it, even when called from submodule
recipes.
Modules may be made optional by putting a
after the
keyword:
Missing source files for optional modules do not produce an error.
Optional modules with no source file do not conflict, so you can have multiple
mod statements with the same name, but with different source file paths, as
long as at most one source file exists:
just
mod? foo 'bar.just'
mod? foo 'baz.just'
Modules may be given doc comments which appear in
output<sup>1.30.0</sup>:
justfile
# foo is a great module!
mod foo
console
$ just --list
Available recipes:
foo ... # foo is a great module!
Modules are still missing a lot of features, for example, the ability to refer
to variables in other modules. See the
module improvement tracking
issue for more information.
Hiding s
looks for
s named
and
, which can be
used to keep a
hidden.
Just Scripts
By adding a shebang line to the top of a
and making it executable,
can be used as an interpreter for scripts:
console
$ cat > script <<EOF
#!/usr/bin/env just --justfile
foo:
echo foo
EOF
$ chmod +x script
$ ./script foo
echo foo
foo
When a script with a shebang is executed, the system supplies the path to the
script as an argument to the command in the shebang. So, with a shebang of
#!/usr/bin/env just --justfile
, the command will be
/usr/bin/env just --justfile PATH_TO_SCRIPT
.
With the above shebang,
will change its working directory to the
location of the script. If you'd rather leave the working directory unchanged,
use
#!/usr/bin/env just --working-directory . --justfile
.
Note: Shebang line splitting is not consistent across operating systems. The
previous examples have only been tested on macOS. On Linux, you may need to
pass the
flag to
:
just
#!/usr/bin/env -S just --justfile
default:
echo foo
Formatting and dumping s
Each
has a canonical formatting with respect to whitespace and
newlines.
You can overwrite the current justfile with a canonically-formatted version
using the currently-unstable
flag:
console
$ cat justfile
# A lot of blank lines
some-recipe:
echo "foo"
$ just --fmt --unstable
$ cat justfile
# A lot of blank lines
some-recipe:
echo "foo"
Invoking
just --fmt --check --unstable
runs
in check mode. Instead of
overwriting the
,
will exit with an exit code of 0 if it is
formatted correctly, and will exit with 1 and print a diff if it is not.
You can use the
command to output a formatted version of the
to stdout:
console
$ just --dump > formatted-justfile
The
command can be used with
to print a JSON
representation of a
.
Fallback to parent s
If a recipe is not found in a
and the
setting is set,
will look for
s in the parent directory and up, until it
reaches the root directory.
will stop after it reaches a
in
which the
setting is
or unset.
As an example, suppose the current directory contains this
:
just
set fallback
foo:
echo foo
And the parent directory contains this
:
console
$ just bar
Trying ../justfile
echo bar
bar
Avoiding Argument Splitting
just
foo argument:
touch {{argument}}
The following command will create two files,
and
:
console
$ just foo "some argument.txt"
The user's shell will parse
as a single argument, but
when
replaces
with
, the
quotes are not preserved, and
will receive two arguments.
There are a few ways to avoid this: quoting, positional arguments, and exported
arguments.
Quoting
Quotes can be added around the
interpolation:
just
foo argument:
touch '{{argument}}'
This preserves
's ability to catch variable name typos before running,
for example if you were to write
, but will not do what you want
if the value of
contains single quotes.
Positional Arguments
The
setting causes all arguments to be passed as
positional arguments, allowing them to be accessed with
,
, …, and
, which can be then double-quoted to avoid further splitting by the shell:
just
set positional-arguments
foo argument:
touch "$1"
This defeats
's ability to catch typos, for example if you type
instead of
, but works for all possible values of
, including
those with double quotes.
Exported Arguments
All arguments are exported when the
setting is set:
just
set export
foo argument:
touch "$argument"
Or individual arguments may be exported by prefixing them with
:
just
foo $argument:
touch "$argument"
This defeats
's ability to catch typos, for example if you type
, but works for all possible values of
, including those
with double quotes.
Configuring the Shell
There are a number of ways to configure the shell for linewise recipes, which
are the default when a recipe does not start with a
shebang. Their
precedence, from highest to lowest, is:
- The and command line options. Passing either of
these will cause to ignore any settings in the current justfile.
set windows-shell := [...]
- (deprecated)
Since
has higher precedence than
, you can use
to pick a shell on Windows, and
to pick a shell
for all other platforms.
Timestamps
can print timestamps before each recipe commands:
just
recipe:
echo one
sleep 2
echo two
$ just --timestamp recipe
[07:28:46] echo one
one
[07:28:46] sleep 2
[07:28:48] echo two
two
By default, timestamps are formatted as
. The format can be changed
with
:
$ just --timestamp recipe --timestamp-format '%H:%M:%S%.3f %Z'
[07:32:11:.349 UTC] echo one
one
[07:32:11:.350 UTC] sleep 2
[07:32:13:.352 UTC] echo two
two
The argument to
is a
-style format string, see
the
library docs
for details.
Signal Handling
Signals are messsages sent to
running programs to trigger specific behavior. For example,
is sent to
all processes in the terminal forground process group when
is pressed.
tries to exit when requested by a signal, but it also tries to avoid
leaving behind running child proccesses, two goals which are somewhat in
conflict.
If
exits leaving behind child processes, the user will have no recourse
but to
for the children and manually
them, a tedious
endevour.
Fatal Signals
,
, and
are generated when the user closes the
terminal, types
, or types
, respectively, and are sent to all
processes in the foreground process group.
is the default signal sent by the
command, and is delivered
only to its intended victim.
When a child process is not running,
will exit immediately on receipt of
any of the above signals.
When a child process
is running,
will wait until it terminates, to
avoid leaving it behind.
Additionally, on receipt of
,
will forward
to any
running children<sup>1.41.0</sup>, since unlike other fatal signals,
,
was likely sent to
alone.
Regardless of whether a child process terminates successfully after
receives a fatal signal,
halts execution.
is sent to all processes in the foreground process group when the
user types
on
BSD-derived
operating systems, including MacOS, but not Linux.
responds by printing a list of all child process IDs and
commands<sup>1.41.0</sup>.
Windows
On Windows,
behaves as if it had received
when the user types
. Other signals are unsupported.