You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
This will load the script behind prelude@maxandersen 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.
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.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Changelog
Buckle up - this is a fun release enabling some long-awaited mythical features!
cat logs.txt | jbang -s prelude@maxandersen -c '$$(l -> l.s(2))'
jbang tree@xam.dk
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 adduse 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: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@maxandersen -c '$$(l -> l.s(2))'
This will load the script behind
prelude@maxandersen
which provides a method named$$
which iterates all input and give you a
Line
instance where there are various methods to extractcontent, 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 inhttps://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 ratherthan 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:
which setup the path printed by
sdk home java 18-open
to be what what JBang treat as Java 18.Then you can run:
🚀 Features
--sources script@repo
work (feat: Made--sources script@repo
work #1283)🐛 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
This discussion was created from the release v0.91.0.
Beta Was this translation helpful? Give feedback.
All reactions