Show Menu

Just is a command runner

Simple justfile

#!/usr/bin/env just --justfile

# hello is recipe's name
  echo "Hello World!"

default Recipe

default: lint build test

# default recipe to display help information
  @just --list

# if no default recipe, first recipe will be default


alias t := test
alias c := check


set shell := ["zsh", "-cu"] 

set dotenv-load := true
   echo "$DATABASE_ADDRESS from .env"

set positional-arguments := true
  echo $0
  echo $1

Strings - escape with Double­-quoted

string-with-tab := "\t"
string-with-newline := "\n"
escapes := '\t\n\r\"\\'

# this string will evaluate to `foo\nbar\n`
x := '''

just command line

# run recipe
$ just hello param1

# list recipes in alphab­etical order
$ just --list
$ just --summary

# Show full inform­ation about recipe
just --show test

# select recipes to run intera­ctively
$ just --choose

# shell completion
just --comp­letions zsh

GitHub Actions

- uses: extractions/setup-just@v1
    just-version: 0.10.5

IDE integr­ation


Recipe with parameters

filter PATTERN:
   echo {{PATTERN}}

# param with default value
email address='':
   echo {{address}}

# param with expression
test triple=(arch() + "-unknown-unknown"):
  ./test {{triple}}

# variadic param: '+' aceept one or more values
backup +FILES:
  scp {{FILES}}

# variadic param with *: zero or more values
  git commit {{FLAGS}} -m "{{MESSAGE}}"

Recipe with env variable for command

# recipe param as env variable with $ sign
hello $name:
   echo $name

Recipe Depend­encies - Before, After & Around

# execution sequence:  a -> b -> c -> d 
b: a && c d

# execute recipe 'a'  around
  echo 'B start!'
  just a
  echo 'B end!'

# depend with params by expression
default: (build "main")

build target:
  @echo 'Building {{target}}...'

Command annotate: quiet(@), suppre­ss(-), invert(!)

  @ echo "command will not be echoed"
  - echo "ignore none-zero exit status and continue"

  echo "command will not be echoed"

# Invert command exit status by !  - shell feature
  # if command succeeds(exit status is 0), exit just
  ! git branch | grep '* master'

Recipe with other Languages

    #!/usr/bin/env bash
    set -euxo pipefail
    echo "$hello from bash!"

Private Recipes - name starts with _

test: _test-helper

# ommited from 'just --list'

Recipes as shell alias

for recipe in `just -f ~/.justfile --summary`; do
  alias $recipe="just -f ~/.justfile -d. $recipe"

Variable and Substi­tution

version := "0.2.7"
tardir  := "awesomesauce-" + version
tarball := tardir + ".tar.gz"

   echo {{version}}

# set/override variables from just command line
$ just --set version 1.1.0

Enviro­nment variable for commands

export RUST_BACKTRACE := "1"

    # will print a stack trace if it crashes
    cargo test

backtick - capture output from evaluation

JAVA_HOME := `jbang jdk home 11`
#  backtick code block
stuff := ```
   echo $foo "world"

done BRANCH=`git rev-parse --abbrev-ref HEAD`:
  git checkout master

    @echo "`wc -l *.c` lines of code"

# backtick works anywhere:  string/variable/params

Just functions

hello name:
   echo {{os()}}
   echo {{uppercase(name)}}

# function categories
* System Information
* Environment Variables
* Justfile and Justfile Directory
* String Manipulation
* Path Manipulation

# String contact:  (key + ":" + value)

Condit­ional expres­sions: if, loop and while

# regular expression match
fo := if "hi" =~ 'h.+' { "match" } else { "mismatch" }

   if true; then echo 'True!'; fi
   for file in `ls .`; do echo $file; done
   while `server-is-dead`; do ping -c 1 server; done

foo bar:
  echo {{ if bar == "bar" { "hello" } else { "bye" } }}


# Each command line is executed by a new shell.
# If a command line failed, just will exit, \
# and subsequent command lines will not be executed.
   cd bar && pwd
   # multi-line construct - escape newline with slash
   if true; then \
        echo 'True!'; \

# justfile is case insensitive: Justfile, JUSTFILE etc
# justfile could be hidden:  '.justfile'
# Call recipe from sub dir:  `~/app1/target>$ just build`


Helpful thanks!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          More Cheat Sheets by linux_china

          JBang Cheat Sheet
          httpx Cheat Sheet