Just -- Command Runner
Have you ever think of a simple tool to just run simple commands?
The Problem
I’ll give my real project needs as an example. I hate to write these same commands over and over to this blog:
hugo server -D
ls content/posts
hugo new content/posts/FILE.md
nano content/posts/FILE.md
I hate to memorize or read what command to what in every project. I needed a script to run that simple commands.
Also, I love using alias, but I didn’t want to fill my shell config file with project related alias.
My first options were a bash script or a makefile, but they are cumbersome and difficult to maintain (sometimes, to read too).
Then I searched for something in the programming language the project uses, but nothing there I liked.
After this example, do you feel my tiredness? Have you ever got you “going up” in the shell history, just to search that command?
And, if the history shell is deleted? And, if you didn’t wrote down the command needed?
The Solution
After some researched, I found that I was looking for a command runner, not a builder system!
A simple example of a command runner can the the npm scripts (not the npm itself). But, as you guessed, this is not language agnostic.
So, I researched for a command runner, and found just
justis a handy way to save and run project-specific commands.Commands, called recipes, are stored in a file called
justfile, or.justfile, with syntax inspired bymake.justhas a ton of useful features, and many improvements overmake.
I was surprised and somewhat skeptic. How this can be so simple?
The Tool
This tool has so many features, but today I only use the very basic.
Nevertheless, I’ll hightlight the must useful ones to me:
- Recipes can accept command line arguments.
- Wherever possible, errors are resolved statically. Unknown recipes and circular dependencies are reported before anything runs.
- Recipes can be listed from the command line (
just --list). - Recipes can be written in arbitrary languages, like Python or NodeJS.
The Example
Take the .justfile from this blog:
alias d := default
alias b := build
alias s := server
alias w := server
alias lp := list-posts
alias np := new-post
default: server
build:
@hugo
server:
@hugo server --buildDrafts
new-post FILE:
@hugo new content/posts/{{FILE}}.md
@nano content/posts/{{FILE}}.md
list-posts:
@ls content/posts/
Let’s break down it:
- It has
aliasfor the recipes configured. - The
defaultrecipe is always involked when calling onlyjust. Also, we can assign other recipes to one another. - The use of
@prevents outputing the command itself. - In the
new-postrecipe, you can see how I used a parameter to pass along the recipe commands'.
I hope you’ve enjoyed this discovery. More to coming …
Website: https://just.systems/
Github: https://github.com/casey/just
Cheatsheet: https://cheatography.com/linux-china/cheat-sheets/justfile/