Just - A Simple Command Runner

Just - A Simple Command Runner

just is a handy way to save and run project-specific commands.

Syed Jafer K's photo
Syed Jafer K
·Sep 19, 2022·

2 min read

Subscribe to our newsletter and never miss any upcoming articles

Play this article

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:

How it works:

  1. We just need to create a file named justfile or JustFile.
  2. 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"
  1. Execute the file using just.

image.png

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"

image.png

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"

image.png

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"

image.png

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"

image.png

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"

image.png

Checkout this link for more features. Hope you liked it.

Did you find this article valuable?

Support Make Reading by becoming a sponsor. Any amount is appreciated!

Learn more about Hashnode Sponsors
 
Share this