Skip to content

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

  • Change: append asdf_update_java_home to $env.config.hooks.pre_prompt
  • Reason: keeps JAVA_HOME/JDK_HOME in sync during interactive use without requiring manual invocation.

No behavior change 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.

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