jbang icon indicating copy to clipboard operation
jbang copied to clipboard

feat: export an additional env var pointing to the location of jbang

Open dsyer opened this issue 1 year ago • 3 comments

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?

dsyer avatar Jun 20 '24 06:06 dsyer

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.

maxandersen avatar Jun 20 '24 10:06 maxandersen

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.

dsyer avatar Jun 20 '24 11:06 dsyer

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?

maxandersen avatar Jun 27 '24 16:06 maxandersen

@all-contributors please add @dsyer for code

maxandersen avatar Jul 06 '24 09:07 maxandersen

@maxandersen

I've put up a pull request to add @dsyer! :tada:

allcontributors[bot] avatar Jul 06 '24 09:07 allcontributors[bot]