Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ For fish shell, instead use:

`. ~/.asdf/plugins/java/set-java-home.fish`

For nushell shell, instead use:
For nushell shell, add the following to `config.nu`:

`source ~/.asdf/plugins/java/set-java-home.nu`

Expand Down
22 changes: 13 additions & 9 deletions set-java-home.nu
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
def asdf_update_java_home [] {
let $java_path = (asdf which java)

if $java_path {
let $full_path = (realpath $java_path | lines | nth 0 | str trim)

let $java_home = ($full_path | path dirname | path dirname)
$env.JAVA_HOME = $java_home
$env.JDK_HOME = $java_home
def --env asdf-update-java-home [] {
let java_path = asdf which java | complete
if $java_path.exit_code == 0 {
let full_path = ($java_path.stdout | str trim | path expand)
let java_home = ($full_path | path dirname | path dirname)
if $java_home != ($env.JAVA_HOME? | default "") {
$env.JAVA_HOME = $java_home
$env.JDK_HOME = $java_home
}
}
}

$env.config.hooks.pre_prompt = (
$env.config.hooks | get -o pre_prompt | default [] | prepend {|| asdf-update-java-home }
)