diff options
Diffstat (limited to 'nushell/autoload')
| -rw-r--r-- | nushell/autoload/mise.nu | 57 | ||||
| -rw-r--r-- | nushell/autoload/zoxide.nu | 70 |
2 files changed, 127 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 +} diff --git a/nushell/autoload/zoxide.nu b/nushell/autoload/zoxide.nu new file mode 100644 index 0000000..e22671c --- /dev/null +++ b/nushell/autoload/zoxide.nu @@ -0,0 +1,70 @@ +# Code generated by zoxide. DO NOT EDIT. + +# ============================================================================= +# +# Hook configuration for zoxide. +# + +# Initialize hook to add new entries to the database. +export-env { + $env.config = ( + $env.config? + | default {} + | upsert hooks { default {} } + | upsert hooks.env_change { default {} } + | upsert hooks.env_change.PWD { default [] } + ) + let __zoxide_hooked = ( + $env.config.hooks.env_change.PWD | any { try { get __zoxide_hook } catch { false } } + ) + if not $__zoxide_hooked { + $env.config.hooks.env_change.PWD = ($env.config.hooks.env_change.PWD | append { + __zoxide_hook: true, + code: {|_, dir| ^zoxide add -- $dir} + }) + } +} + +# ============================================================================= +# +# When using zoxide with --no-cmd, alias these internal functions as desired. +# + +# Jump to a directory using only keywords. +export def --env --wrapped __zoxide_z [...rest: directory] { + let path = match $rest { + [] => {'~'}, + [ '-' ] => {'-'}, + [ $arg ] if ($arg | path expand | path type) == 'dir' => {$arg} + _ => { + ^zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n" + } + } + cd $path +} + +# Jump to a directory using interactive search. +export def --env --wrapped __zoxide_zi [...rest: string] { + cd $'(^zoxide query --interactive -- ...$rest | str trim -r -c "\n")' +} + +# ============================================================================= +# +# Commands for zoxide. Disable these using --no-cmd. +# + +export alias z = __zoxide_z +export alias zi = __zoxide_zi + +# ============================================================================= +# +# Add this to your env file (find it by running `$nu.env-path` in Nushell): +# +# zoxide init nushell | save -f ~/.zoxide.nu +# +# Now, add this to the end of your config file (find it by running +# `$nu.config-path` in Nushell): +# +# source ~/.zoxide.nu +# +# Note: zoxide only supports Nushell v0.89.0+. |
