Skip to content

Fix JAVA_HOME/JDK_HOME handling in set-java-home.nu for Nushell#262

Open
HaaaaE wants to merge 2 commits intohalcyon:masterfrom
HaaaaE:fix/nushell-java-home-handling
Open

Fix JAVA_HOME/JDK_HOME handling in set-java-home.nu for Nushell#262
HaaaaE wants to merge 2 commits intohalcyon:masterfrom
HaaaaE:fix/nushell-java-home-handling

Conversation

@HaaaaE
Copy link

@HaaaaE HaaaaE commented Feb 1, 2026

Nushell has changed a lot since set-java-home.nu was last updated.

This PR fixes errors and makes the script more robust.

Changes in set-java-home.nu and reasons:

Use an env-aware function definition

  • Change: defdef --env
  • Reason: environment-variable updates should be performed inside an --env function so they reliably affect the caller environment.

Handle command execution results explicitly

  • Change: replace direct let java_path = (asdf which java) with:
    let result = (do -i { asdf which java } | complete) and a match on { exit_code, stdout }
  • Reason: makes success/failure paths explicit, improves readability, and avoids relying on implicit truthiness of command output.

Make the “no Java available” path safe and deterministic

  • Change: when asdf which java fails or returns empty/whitespace output, clear the variables:
    hide-env -i JAVA_HOME JDK_HOME
  • Reason: prevents stale JAVA_HOME/JDK_HOME values from persisting when the Java tool is not available in the current context.

Remove dependency on realpath and the deprecated nth

  • Change: replace realpath, nth 0 with path expand, first
  • Reason: use Nushell built-in command path expand to replace realpath is recommended by Nushell community. And nth is not available in the newest Nushell version.

Automatically refresh on prompt
Instead of recomputing the Java environment on every prompt, the update now happens only after running asdf commands excluding asdf which and asdf where, or when the working directory changes.
The purpose is to reduce unnecessary prompt-time overhead while keeping the environment variables correct and consistent with asdf’s state.

No behavior change of asdf_update_java_home is intended when asdf which java returns a valid path.

This change primarily improves robustness in error and empty-output cases and aligns the script with current Nushell environment semantics.

Thanks.

…ectory changes

Instead of recomputing the Java environment on every prompt, the update now happens only after running asdf commands excluding asdf which and asdf where, or when the working directory changes. 

The purpose is to reduce unnecessary prompt-time overhead while keeping the environment variables correct and consistent with asdf’s state.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant