-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathset-java-home.nu
More file actions
48 lines (40 loc) · 1.34 KB
/
Copy pathset-java-home.nu
File metadata and controls
48 lines (40 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def --env asdf_update_java_home [] {
let result = (do -i { asdf which java } | complete)
match $result {
{ exit_code: 0, stdout: $s } if ($s | str trim | is-not-empty) => {
let java_home = (
$s
| lines | first | str trim
| path expand
| path dirname | path dirname
)
$env.JAVA_HOME = $java_home
$env.JDK_HOME = $java_home
}
_ => { hide-env -i JAVA_HOME JDK_HOME }
}
}
def is-asdf-mutating []: string -> bool {
let s = ($in | str trim)
if not ($s like '^\^?asdf(\s|$)') { return false }
if ($s like '^\^?asdf\s+(which|where)(\s|$)') { return false }
true
}
def --env pre_execution_hook [] {
let line = (commandline)
if ($line | is-asdf-mutating) {
$env._ASDF_REFRESH_NEEDED = true
} else {
hide-env -i _ASDF_REFRESH_NEEDED
}
}
def --env pre_prompt_hook [] {
if ($env._ASDF_REFRESH_NEEDED? | default false) {
asdf_update_java_home
hide-env -i _ASDF_REFRESH_NEEDED
}
}
$env.config.hooks = $env.config.hooks
| upsert pre_execution { $in | default [] | append { pre_execution_hook } }
| upsert pre_prompt { $in | default [] | append { pre_prompt_hook } }
| upsert env_change.PWD { $in | default [] | append { asdf_update_java_home } }