Fix JAVA_HOME/JDK_HOME handling in set-java-home.nu for Nushell #262
+19
−9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Nushell has changed a lot since
set-java-home.nuwas last updated.This PR fixes errors and makes the script more robust.
Changes in
set-java-home.nuand reasons:Use an env-aware function definition
def→def --env--envfunction so they reliably affect the caller environment.Handle command execution results explicitly
let java_path = (asdf which java)with:let result = (do -i { asdf which java } | complete)and a match on{ exit_code, stdout }Make the “no Java available” path safe and deterministic
hide-env -i JAVA_HOME JDK_HOMEJAVA_HOME/JDK_HOMEvalues from persisting when the Java tool is not available in the current context.Remove dependency on
realpathand the deprecatednthrealpath,nth 0withpath expand,firstpath expandto replacerealpathis recommended by Nushell community. Andnthis not available in the newest Nushell version.Automatically refresh on prompt
asdf_update_java_hometo$env.config.hooks.pre_promptJAVA_HOME/JDK_HOMEin sync during interactive use without requiring manual invocation.No behavior change is intended when
asdf which javareturns a valid path.This change primarily improves robustness in error and empty-output cases and aligns the script with current Nushell environment semantics.
Thanks.