Just - A Simple Command Runner
Introduction
Just is a handy way to save and run project-specific commands. Commands are stored in a file called justfile or Justfile with syntax inspired by make:
- Official Website: https://just.systems/
- Official Documentation: https://just.systems/man/en
- Git Reposity: https://github.com/casey/just
- Examples: https://github.com/casey/just/tree/master/examples
How it works:
- We just need to create a file named
justfile
orJustFile
. - Then we need to add command(s) in a groupwise manner under a name, as given below.
hello: # <- Group Name
# List of commands to be executed in order.
echo "Hello !"
echo "This will be executed next"
- Execute the file using
just
.
Some cool features
1. We can have a default group, which would be executed when we aren't specifying the group name.
default:
echo "Default !!"
hello: # <- Group Name
# List of commands to be executed in order.
echo "Hello !"
echo "This will be executed next"
2. Each group is called as recipe's. We can have multiple recipe's name in the default recipe to execute them in order.
default: hello greet
hello: # <- Group Name
# List of commands to be executed in order.
echo "Hello !"
echo "This will be excuted next"
greet:
echo "Hi How are you"
3. We can also use dotenv files with justfile.
.env
# a comment, will be ignored
POSTGRES=localhost:6379
PORT=5004
justfile
set dotenv-load
serve:
echo "Starting the server with database $POSTGRES on port $PORT"
4. Usually when an error happens in a sequence of commands, the next commands will not run. But with justfile we can ignore the errors using hypen as a prefix (-cat
).
foo:
-cat foo
echo "Done"
5. We can also use conditional expressions with just. 6. Changing variable values from command line itself. 7. Remember that each line will be executed in a fresh shell, so if you are changing directory in a line, it won't affect the other line. 8. By using @ symbol it won't echo the commands that we wrote.
hello:
@echo "Done"
Checkout this link for more features. Hope you liked it.
Subscribe to my newsletter
Read articles from Syed Jafer K directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by