0% found this document useful (0 votes)
17 views2 pages

Linux China Justfile

Uploaded by

310788.julio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

Linux China Justfile

Uploaded by

310788.julio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Justfile Cheat Sheet

by linux_china via cheatography.com/141366/cs/30282/

Simple justfile just command line Recipe with parameters (cont)

#!/usr/bin/env just --justfile # run recipe > commit MESSAGE *FLAGS:


# hello is recipe's name $ just hello param1 ​ git commit {{FLAGS}} -m "{{MESSAGE}}"
hello: # list recipes in alphab​etical order
​ echo "​Hello World!​" $ just --list Recipe with env variable for command
$ just --summary
# recipe param as env variable
default Recipe # Show full inform​ation about recipe
with $ sign
just --show test
default: lint build test hello $name:
# select recipes to run intera​ctively
# default recipe to display help ​ ​ echo $name
$ just --choose
inform​ation
# shell completion
default: Recipe Depend​encies - Before, After &
just --comp​letions zsh
​ ​@just --list Around

# if no default recipe, first GitHub Actions # execution sequence: a -> b ->


recipe will be default c -> d
- uses: extractions/setup-
b: a && c d
just@v1
Aliases # execute recipe 'a' around
​ ​with:
alias t := test b:
​ ​ ​ ​jus​t-v​ersion: 0.10.5
alias c := check ​ echo 'B start!'
​ just a
IDE integr​ation
Settings ​ echo 'B end!'
VS Code: https:​//m​ark​etp​lac​e.v​isu​als​tud​‐
# depend with params by
set shell := ["zsh", "-cu"] io.c​om​/it​ems​?it​emN​ame​=sk​ell​ock.just
expression
set dotenv​-load := true
JetBrains: https:​//p​lug​ins.je​tbr​ain​s.c​om/​plu​‐
default: (build "​mai​n")
serv: gin​/18​658​-just
build target:
​ ​ echo "​$DA​TAB​ASE​_AD​‐
​ ​@echo 'Building
DRESS from .env" Recipe with parameters
{{target}}...'
set positi​ona​l-a​rgu​ments :=
filter PATTERN:
true
​ ​ echo {{PATTERN}} Command annotate: quiet(@), suppre​ss(-),
foo:
# param with default value invert(!)
​ echo $0
email addres​s='​mas​ter​@ex​‐
​ echo $1 hello:
amp​le.c​om':
​ @ echo "​command will not be
​ ​ echo {{address}}
Strings - escape with Double​-quoted echoed​"
# param with expression
​ - echo "​ignore none-zero
string-with-tab := "\t" test triple​=(a​rch() + "​-un​‐
exit status and contin​ue"
string​-wi​th-​newline := "​\n" kno​wn-​unk​now​n"):
@hello2:
escapes := '\t\n​\r\"\\' ​ ./test {{triple}}
​ echo "​command will not be
# this string will evaluate to # variadic param: '+' aceept one
echoed​"
`foo\n​bar\n` or more values
# Invert command exit status by
x := ''' backup +FILES:
! - shell feature
​ foo ​ scp {{FILES}} me@exa​mpl​‐
hello3:
​ bar e.com
​ # if command succee​ds(exit
''' # variadic param with *: zero or
status is 0), exit just
more values
​ ! git branch | grep '*
master'

By linux_china Published 22nd December, 2021. Sponsored by ApolloPad.com


cheatography.com/linux-china/ Last updated 21st February, 2022. Everyone has a novel in them. Finish
Page 1 of 2. Yours!
https://apollopad.com
Justfile Cheat Sheet
by linux_china via cheatography.com/141366/cs/30282/

Recipe with other Languages backtick - capture output from evaluation Attention

bash-test: JAVA_HOME := `jbang jdk home 11` # Each command line is executed
​ ​ ​ ​#!/​usr​/bi​n/env bash # backtick code block by a new shell.
​ ​ ​ set -euxo pipefail stuff := ``` # If a command line failed, just
​ ​ ​ ​hel​lo='Yo' ​ ​ ​foo​="he​llo​" will exit, \
​ ​ ​ echo "​$hello from bash!" ​ ​ echo $foo "​wor​ld" # and subsequent command lines
``` will not be executed.
Private Recipes - name starts with _ done BRANCH​=`git rev-parse -- change​-wo​rki​ng-dir:

test: _test-helper abbr​ev-ref HEAD`: ​ ​ cd bar && pwd

​ ./b​in/test ​ git checkout master ​ ​ # multi-line construct -

# ommited from 'just --list' sloc: escape newline with slash

_test-​helper: ​ ​ ​ ​@echo "`wc -l *.c` lines ​ ​ if true; then \

​ ./b​in/​sup​er-​sec​ret​-te​‐ of code" ​ ​ ​ ​ ​ ​ ​ echo 'True!'; \

st-​hel​per​-stuff # backtick works anywhere: ​ ​ fi


string​/va​ria​ble​/params # justfile is case insens​itive:
Recipes as shell alias Justfile, JUSTFILE etc
Just functions # justfile could be hidden:
for recipe in `just -f
hello name: '.just​file'
~/.justfile --summary`; do
​ ​ echo {{os()}} # Call recipe from sub dir:
​ ​alias $recip​e="just -f
​ ​ echo {{uppercase(name)}} `~/app​1/t​arg​et>$ just build`
~/.jus​tfile -d. $recip​e"
done # function categories
* System Inform​ation
Variable and Substi​tution * Enviro​nment Variables
* Justfile and Justfile
version := "0.2.7"
Directory
tardir := "​awe​som​esa​uce​-" +
* String Manipu​lation
version
* Path Manipu​lation
tarball := tardir + ".ta​r.g​z"
# String contact: (key + "​:" +
test:
value)
​ ​ echo {{version}}
# set/ov​erride variables from
Condit​ional expres​sions: if, loop and while
just command line
$ just --set version 1.1.0 # regular expression match
fo := if "​hi" =~ 'h.+' { "​‐
Enviro​nment variable for commands mat​ch" } else { "​mis​mat​ch" }
test:
export RUST_BACKTRACE := "1"
​ ​ if true; then echo 'True!';
test:
fi
​ ​ ​ # will print a stack
​ ​ for file in `ls .`; do echo
trace if it crashes
$file; done
​ ​ ​ ​cargo test
​ ​ ​while `serve​r-i​s-d​ead`;
do ping -c 1 server; done
foo bar:
​ echo {{ if bar == "​bar​" {
"​hel​lo" } else { "​bye​" } }}

By linux_china Published 22nd December, 2021. Sponsored by ApolloPad.com


cheatography.com/linux-china/ Last updated 21st February, 2022. Everyone has a novel in them. Finish
Page 2 of 2. Yours!
https://apollopad.com

You might also like