summaryrefslogtreecommitdiff
path: root/nushell/autoload/mise.nu
diff options
context:
space:
mode:
authoreltrac <hi@eltr.ac>2026-09-26 19:44:48 +0800
committereltrac <hi@eltr.ac>2026-09-26 19:44:48 +0800
commitf2c93c07dbdd4eb894ab65f75b760bc895215823 (patch)
tree151e522055a71543e809fe8a02d65391cf43c150 /nushell/autoload/mise.nu
parent015911736d12da19fd168360840c025f22f56696 (diff)
nushell: add nushell configuration
Diffstat (limited to 'nushell/autoload/mise.nu')
-rw-r--r--nushell/autoload/mise.nu57
1 files changed, 57 insertions, 0 deletions
diff --git a/nushell/autoload/mise.nu b/nushell/autoload/mise.nu
new file mode 100644
index 0000000..15c7780
--- /dev/null
+++ b/nushell/autoload/mise.nu
@@ -0,0 +1,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
+}