summaryrefslogtreecommitdiff
path: root/nushell/autoload/mise.nu
blob: 0e0279711f1f952694507cb790ad82f87a566905 (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
58
59
60
61
62
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 {
  
  'hide,LEIN_HOME,
hide,LUA_INIT,
set,PATH,/Users/eltrac/.local/share/pnpm/bin:/Users/eltrac/.local/bin:/Users/eltrac/.local/share/pnpm:/Users/eltrac/.bun/bin:/opt/nanobrew/prefix/bin:/Users/eltrac/bin:/Library/Frameworks/Python.framework/Versions/3.13/bin:/usr/local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/eltrac/.local/share/cargo/bin:/Users/eltrac/.local/share/pnpm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Ghostty.app/Contents/MacOS:/Users/eltrac/Library/Python/3.9/bin:/Users/eltrac/.local/share/go/bin
hide,MISE_SHELL,
hide,__MISE_DIFF,
hide,__MISE_DIFF,' | 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
}