jbang
jbang copied to clipboard
feat: export an additional env var pointing to the location of jbang
It's really hard (impossible?) to find the location of the script that launched the JVM from within jbang. It would be really useful to be able to do that so you can run jbang again with some logic to precompute the command line. This works really simply:
$ jbang --interactive
WARNING: Using incubator modules: jdk.incubator.vector, jdk.incubator.foreign
| Welcome to JShell -- Version 17.0.7
| For an introduction type: /help intro
jshell> System.getenv("JBANG")
$1 ==> "/home/dsyer/.sdkman/candidates/jbang/current/bin/jbang"
Edit: I don't know how to do this for Windows users. Anyone got an idea?
I'm not totally against exporting this variable assuming we find way it works on windows but Thus far we haven't exposed this as its not guaranteed to work.
i.e. the same app could have been run with pure java or native exc launched.
I would prefer some more internal name like JBANG_LAUNCH_SCRIPT or similar.
I don't care about the name really. How about JBANG_LAUNCHER? I get that it's not guaranteed to work if the launcher isn't used, but at least it provides a way to launch jbang in the case that the launcher is used (which is the majority I suspect). I can't think of anything that would work completely generically.
okey, so I pushed code that should work on osx, linux and windows (need ci to verify the latter one).
I also checked what other env vars we actually expose and added tests for those ...BUT I can't actually spot where we use them.. @quintesse can we remove those?
@all-contributors please add @dsyer for code