Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: Just.sh – compiler that turns Justfiles into portable shell scripts (github.com/jstrieb)
64 points by jstrieb on Dec 26, 2023 | hide | past | favorite | 25 comments
Justfiles are like Makefiles, except Just is a command runner, whereas Make is a build system. As I understand it, Just was built to be a less arcane version of Make for collecting commands common to a code repository.

When I first learned about Just, I realized that parsing arguments and running commands is exactly what shell scripts do, and there probably isn't much Just does that sh doesn't. This project proves that hypothesis by compiling Justfiles to portable (POSIX-compatible) shell scripts.

just.sh is particularly useful for running Justfiles in esoteric environments where Just may not be straightforward to install, such as some CI/CD pipeline environments.



I'm a fan of using just as a command-runner as well, but took a slightly different approach to making it pip-installable! I created the `pyjust` package (https://pypi.org/project/pyjust/), which literally just packages the `just` binary in platform-specific wheels, and then unpacks it onto the PATH by leveraging the `scripts` directory unpacking.

Why do this you might ask? My rationale here was that I use `pipx` to install some python CLIs, and it was nice to be able to lump `just` in with that, as well as to be able to declare it as a "dependency" and pin specific versions for distribution.


I love this! I use pipx all the time, and this is perfect workaround on a computer that either does not have Rust and/or requires me to manually download from the repository.

Great idea, and I am wondering if there are more utilities I could/should wrap in a similar fashion. A cross platform brew.


simonw got me interested in the idea after I ran into one of his blogposts talking about how ziglang does it, and then studying ruff + maturin helped me reverse engineer how to accomplish this without any python intermediary in a "python package".

I put together a cruft template (https://github.com/justin-yan/templates-cruft/tree/main/pack...) since I had the exact same thought as you once I got it working - why not do this with a bunch of different tools? I did it with a couple of my favorites (just, lazydocker) but haven't gone back to clean things up/make things a bit more systematic. So it's a pretty messy weekend project (caveat emptor) but hopefully it's a helpful starting point if you want to try it!


I also love this. I might try and adopt this for some utilities as well.


This is fantastic, but I'd say that this solution is somewhat in response to this open issue from 2019:

https://github.com/casey/just/issues/429

I really wish just was included as a package in distributions.


makesure, a similar tool (https://maximullaris.com/makesure-vs-just.html) I'm developing, doesn't require installation in the traditional sense: https://github.com/xonixx/makesure#installation.

Also, I was considering adding the same feature (generating the equivalent shell script) to my tool, but after doing some analysis decided not to pursue this idea for the following reasons: https://github.com/xonixx/makesure/issues/83#issuecomment-98....


Woof, four years. Is packaging really that complicated?


My understanding is that building a .deb is not too hard. The hard part is finding a willing Debian project sponsor to add the package to the archive.

https://wiki.debian.org/DebianMentorsFaq#How_do_I_add_a_new_...


https://repology.org/project/just/versions

Mhm basically only Arch Linux, Chocolatey, FreeBSD, Gentoo and Homebrew. All others are outdated or nonexistent.


I share your wish. This project started out because Just is not apt installable. But at a certain point, it became a "just for fun" project (pun intended).


You're totally right, it is a fun project. The problem is that if I'm writing Justfiles and transpiling them to shell... now I have 3 problems. Just, Python and shell.


Presuming the just.sh compiler is doing everything right, you shouldn't have a shell problem, any more than using C compiler means you now have an assembly-language problem.

Also, the trade-off here (in my mind, at least) is that you could maintain higher-level Justfiles, but distribute releases containing the portable-shell-script artifacts of said compilation — so that anyone using your package doesn't need just, only a POSIX environment.


Yeah.

For an individual.. if you're happy to install `just` in any place you're going to maintain the project, that seems better.

For helping others use the project, providing a bash script which has all the just UX would at least save them from having to install another tool. (Adds one thing for the maintainer, but saves one thing for others to install).


I really like Just, with the only drawback being that you need a Just installation to run a Justfile.

This is a really clever solution to that problem!


This is great! Never knew there was something specific existing as command runner except for arcane or programming-lang specific tools (i.e. Rake, the Cargo one, etc). I have been abusing Makefiles as command runners for years now.


Thanks!

Yeah, Just is pretty awesome! Its biggest drawback over Make is that you can often assume Make is installed, whereas it's not always clear that Just needs to be installed if you've never heard of Justfiles before, let alone how to install it.

There are a few design decisions where I think Just missed an opportunity to improve on Make, but they're all pretty minor.


https://github.com/batsh-dev-team/Batsh

https://github.com/tdenniston/bish

(Just fyi. I've been collecting links to similar things because of Reasons).


Given these examples of a Justfile, it doesn’t seem worth this effort versus using a Makefile and not needing a compilation step (assuming Make is available everywhere). Does anyone have a Justfile example complex enough to demonstrate a significant advantage over Makefile?


I can offer this (warning, crufty real-world scripts ahead!): these make files and bash script (https://github.com/simonmichael/hledger/blob/137d825/Makefil..., https://github.com/simonmichael/hledger/blob/137d825/Makefil..., https://github.com/simonmichael/hledger/blob/a3c300b/bake) were replaced by this roughly equivalent Justfile (https://github.com/simonmichael/hledger/blob/137d825/Justfil...) (some old things were commented out, some new things were added).

I'm only a few weeks in, and just has its own learning curve, but I'm very pleased overall. Cognitive load is down, usability is up, robustness is up. ("After many years with make and plain shell ... for scripting, just is better enough, and the goal of clean consolidated efficient project automation is so valuable, that I am relying on it even though it's not installed by default.")


Just is fundamentally less capable but by extension less complex, and that’s by design. It’s essentially a way to group your shell scripts for a given project. It’s somewhat similar to make in terms of syntax but it doesn’t do anything make does like tracking whether a task needs to be rerun


why use make over sh/bash?


What is the upside compared to just creating the corresponding shell scripts? I can see that one file instead of how many more is better, but it's also one thing more to worry about and confuse people on your project, surely there's more to it?


Assuming the compilation is perfect, it lets the author maintain the simple Just format, while simultaneously distributing the same code to a runtime (shell) that is installed everywhere. Lowers the barrier of entry. Also, my quick glance at the just.sh output, it introduces a lot of niceties most people are not going to include in their own shell scripts.

I love Just. Corrects many of Makes hindsight-mistakes, and centralizes all of your project tasks for an easy to browse summary. Even if each task is essentially `bash scripts/dothing.sh`, the single source is nice.


I reckon just is 'low-medium benefit for low effort'. There's some nice UX to it, but I think a substantial benefit to it is having one place where you organise "these are the tasks that get run".

In response to "Why just not make" or "why just not bash script", I'd say "UX improvements for next to no effort".. or perhaps a conventional entry point for what tasks to run.

Having a transpiled bash script from a justfile has the benefit of not needing just installed.


Does it have bash autocompletion support?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: