Functions
just
provides a few built-in functions that might be useful when writing recipes.
System Information
arch()
— Instruction set architecture. Possible values are:"aarch64"
,"arm"
,"asmjs"
,"hexagon"
,"mips"
,"msp430"
,"powerpc"
,"powerpc64"
,"s390x"
,"sparc"
,"wasm32"
,"x86"
,"x86_64"
, and"xcore"
.num_cpus()
- Number of logical CPUs.os()
— Operating system. Possible values are:"android"
,"bitrig"
,"dragonfly"
,"emscripten"
,"freebsd"
,"haiku"
,"ios"
,"linux"
,"macos"
,"netbsd"
,"openbsd"
,"solaris"
, and"windows"
.os_family()
— Operating system family; possible values are:"unix"
and"windows"
.
For example:
system-info:
@echo "This is an {{arch()}} machine".
$ just system-info
This is an x86_64 machine
The os_family()
function can be used to create cross-platform justfile
s that work on various operating systems. For an example, see cross-platform.just file.
Environment Variables
env_var(key)
— Retrieves the environment variable with namekey
, aborting if it is not present.
home_dir := env_var('HOME')
test:
echo "{{home_dir}}"
$ just
/home/user1
env_var_or_default(key, default)
— Retrieves the environment variable with namekey
, returningdefault
if it is not present.
Invocation Directory
invocation_directory()
- Retrieves the absolute path to the current directory whenjust
was invoked, beforejust
changed it (chdir’d) prior to executing commands. On Windows,invocation_directory()
usescygpath
to convert the invocation directory to a Cygwin-compatible/
-separated path. Useinvocation_directory_native()
to return the verbatim invocation directory on all platforms.
For example, to call rustfmt
on files just under the “current directory”
(from the user/invoker’s perspective), use the following rule:
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.):
build:
cd {{invocation_directory()}}; ./some_script_that_needs_to_be_run_from_here
invocation_directory_native()
- Retrieves the absolute path to the current directory whenjust
was invoked, beforejust
changed it (chdir’d) prior to executing commands.
Justfile and Justfile Directory
-
justfile()
- Retrieves the path of the currentjustfile
. -
justfile_directory()
- Retrieves the path of the parent directory of the currentjustfile
.
For example, to run a command relative to the location of the current justfile
:
script:
./{{justfile_directory()}}/scripts/some_script
Just Executable
just_executable()
- Absolute path to thejust
executable.
For example:
executable:
@echo The executable is at: {{just_executable()}}
$ just
The executable is at: /bin/just
String Manipulation
quote(s)
- Replace all single quotes with'\''
and prepend and append single quotes tos
. This is sufficient to escape special characters for many shells, including most Bourne shell descendants.replace(s, from, to)
- Replace all occurrences offrom
ins
toto
.replace_regex(s, regex, replacement)
- Replace all occurrences ofregex
ins
toreplacement
. Regular expressions are provided by the Rustregex
crate. See the syntax documentation for usage examples.trim(s)
- Remove leading and trailing whitespace froms
.trim_end(s)
- Remove trailing whitespace froms
.trim_end_match(s, pat)
- Remove suffix ofs
matchingpat
.trim_end_matches(s, pat)
- Repeatedly remove suffixes ofs
matchingpat
.trim_start(s)
- Remove leading whitespace froms
.trim_start_match(s, pat)
- Remove prefix ofs
matchingpat
.trim_start_matches(s, pat)
- Repeatedly remove prefixes ofs
matchingpat
.
Case Conversion
capitalize(s)
1.7.0 - Convert first character ofs
to uppercase and the rest to lowercase.kebabcase(s)
1.7.0 - Converts
tokebab-case
.lowercamelcase(s)
1.7.0 - Converts
tolowerCamelCase
.lowercase(s)
- Converts
to lowercase.shoutykebabcase(s)
1.7.0 - Converts
toSHOUTY-KEBAB-CASE
.shoutysnakecase(s)
1.7.0 - Converts
toSHOUTY_SNAKE_CASE
.snakecase(s)
1.7.0 - Converts
tosnake_case
.titlecase(s)
1.7.0 - Converts
toTitle Case
.uppercamelcase(s)
1.7.0 - Converts
toUpperCamelCase
.uppercase(s)
- Converts
to uppercase.
Path Manipulation
Fallible
absolute_path(path)
- Absolute path to relativepath
in the working directory.absolute_path("./bar.txt")
in directory/foo
is/foo/bar.txt
.extension(path)
- Extension ofpath
.extension("/foo/bar.txt")
istxt
.file_name(path)
- File name ofpath
with any leading directory components removed.file_name("/foo/bar.txt")
isbar.txt
.file_stem(path)
- File name ofpath
without extension.file_stem("/foo/bar.txt")
isbar
.parent_directory(path)
- Parent directory ofpath
.parent_directory("/foo/bar.txt")
is/foo
.without_extension(path)
-path
without extension.without_extension("/foo/bar.txt")
is/foo/bar
.
These functions can fail, for example if a path does not have an extension, which will halt execution.
Infallible
clean(path)
- Simplifypath
by removing extra path separators, intermediate.
components, and..
where possible.clean("foo//bar")
isfoo/bar
,clean("foo/..")
is.
,clean("foo/./bar")
isfoo/bar
.join(a, b…)
- This function uses/
on Unix and\
on Windows, which can be lead to unwanted behavior. The/
operator, e.g.,a / b
, which always uses/
, should be considered as a replacement unless\
s are specifically desired on Windows. Join patha
with pathb
.join("foo/bar", "baz")
isfoo/bar/baz
. Accepts two or more arguments.
Filesystem Access
path_exists(path)
- Returnstrue
if the path points at an existing entity andfalse
otherwise. Traverses symbolic links, and returnsfalse
if the path is inaccessible or points to a broken symlink.
Error Reporting
error(message)
- Abort execution and report errormessage
to user.
UUID and Hash Generation
sha256(string)
- Return the SHA-256 hash ofstring
as a hexadecimal string.sha256_file(path)
- Return the SHA-256 hash of the file atpath
as a hexadecimal string.uuid()
- Return a randomly generated UUID.