blob: 15c7780a6d790525d575ffef302f7909ee9834ac (
plain)
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
49
50
51
52
53
54
55
56
57
|
def "parse vars" [] {
$in | from csv --noheaders --no-infer | rename 'op' 'name' 'value'
}
def --env "update-env" [] {
for $var in $in {
if $var.op == "set" {
if ($var.name | str uppercase) == 'PATH' {
$env.PATH = ($var.value | split row (char esep))
} else {
load-env {($var.name): $var.value}
}
} else if $var.op == "hide" and $var.name in $env {
hide-env $var.name
}
}
}
export-env {
'' | parse vars | update-env
$env.MISE_SHELL = "nu"
let mise_hook = {
condition: { "MISE_SHELL" in $env }
code: { mise_hook }
}
add-hook hooks.pre_prompt $mise_hook
add-hook hooks.env_change.PWD $mise_hook
}
def --env add-hook [field: cell-path new_hook: any] {
let field = $field | split cell-path | update optional true | into cell-path
let old_config = $env.config? | default {}
let old_hooks = $old_config | get $field | default []
$env.config = ($old_config | upsert $field ($old_hooks ++ [$new_hook]))
}
export def --env --wrapped main [command?: string, --help, ...rest: string] {
let commands = ["deactivate", "shell", "sh"]
if ($command == null) {
^"/Users/eltrac/.local/bin/mise"
} else if ($command == "activate") {
$env.MISE_SHELL = "nu"
} else if ($command in $commands) {
^"/Users/eltrac/.local/bin/mise" $command ...$rest
| parse vars
| update-env
} else {
^"/Users/eltrac/.local/bin/mise" $command ...$rest
}
}
def --env mise_hook [] {
^"/Users/eltrac/.local/bin/mise" hook-env -s nu
| parse vars
| update-env
}
|