github jbangdev/jbang v0.91.0

latest releases: v0.132.1, v0.132.0, v0.131.0...
3 years ago

Changelog

Buckle up - this is a fun release enabling some long-awaited mythical features!

  • Aliases for sources: cat logs.txt | jbang -s prelude@maxandersen -c '$$(l -> l.s(2))'
  • Websites as implicit catalog jbang tree@xam.dk
  • Custom JDK Install: j! jdk install 18 $(sdk home java 18-open)

Details below:

Use of aliases for sources

You can now use an alias to load additional sources, i.e. jbang -s myscript@mycatalog ... - all thanks to @quintesse super refactoring!.

At first, that might not look that interesting but combining it with the previous release where we added support
for running snippets with jbang -c you can now load in a custom source that fetches dependencies and add
use case-specific top-level methods and classes.

As an example I'll use Edoardo Vacchi's idea about implementing AWK in JBang using a script called Prelude.jsh.

Imagine you have a logs.txt with the following content:

GET /robots.txt HTTP/1.1
HEAD /README.md HTTP/1.1
GET /wp-admin/ HTTP/1.0

And you want to print out all the paths in that log.

There is a ton of ways to do that but if you use raw java it might be quite verbose.

Now with aliases we can cut this down to:

cat logs.txt | jbang -s prelude@evacchi -c '$$(l -> l.s(2))'

This will load the script behind prelude@evacchi which provides a method named $$
which iterates all input and give you a Line instance where there are various methods to extract
content, i.e. l.s(2) gives you the second column.

You can load multiple scripts from anywhere making it possible for everyone to make
interesting toplevel methods available to do useful things like the AWK example above; or maybe
just to make it fun/easier to try out your framework/api.

Looking forward to see what crazy ways you find to use this.

Websites as implicit catalog

Until now jbang's implicit catalogs allow you to have a jbang-catalog repository, i.e. @maxandersen was shorthand for catalog found in https://github.com/maxandersen/jbang-catalog. Very useful to have short and recognizable names.

Thus now if there is a '.' in the name jbang will lookup a website with that name first.

For example: jbang tree@xam.dk will use the catalog available at https://xam.dk/jbang-catalog.json.

There are more ways this can be used and expanded - those are covered in the docs.

Install of custom JDK's

We've had many requests on having jbang utilize existing Java installs on your machine rather
than download Java separately. i.e. use sdkman's jdk installs.

We don't do that for various reasons (mainly portability), but with @nandorholozsnyak's great contribution you
can now install custom JDK's using: jbang jdk install <version> <pathtojdk>.

Example:

Lets say you use sdkman and you want to try out Java 18 with JBang - something that today will fail
unless you have Java 18 installed as default jdk.

You can then run:

j! jdk install 18 `sdk home java 18-open`

which setup the path printed by sdk home java 18-open to be what what JBang treat as Java 18.

Then you can run:

j! --java 18 -c 'println(javax.lang.model.SourceVersion.RELEASE_18)'

🚀 Features

🐛 Fixes

♻️ Changes

Contributors

We'd like to thank the following people for their contributions:
Tako Schotanus, Max Rydahl Andersen, GitHub, Pierre-Yves Fourmond, Nándor Holozsnyák

Don't miss a new jbang release

NewReleases is sending notifications on new releases.