{%- let section = "# =============================================================================\n#" -%} {%- let not_configured = "# -- not configured --" -%} # Code generated by zoxide. DO NOT EDIT. {{ section }} # Hook configuration for zoxide. # {% if hook == InitHook::None -%} {{ not_configured }} {%- else -%} # Initialize hook to add new entries to the database. export-env { {%- if hook == InitHook::Prompt %} $env.config = ( $env.config? | default {} | upsert hooks { default {} } | upsert hooks.pre_prompt { default [] } ) let __zoxide_hooked = ( $env.config.hooks.pre_prompt | any { try { get __zoxide_hook } catch { false } } ) if not $__zoxide_hooked { $env.config.hooks.pre_prompt = ($env.config.hooks.pre_prompt | append { __zoxide_hook: true, code: {|| if $env.__zoxide_current_dir != $env.PWD { let now = (date now | format date '%s' | into int) let elapsed = $now - $env.__zoxide_entered_at if $elapsed >= $env.__zoxide_rest_threshold and ($env.__zoxide_current_dir | is-not-empty) { $env.__zoxide_last_rested = $env.__zoxide_current_dir } $env.__zoxide_entered_at = $now $env.__zoxide_current_dir = $env.PWD } ^zoxide add -- $env.PWD } }) } {%- else if hook == InitHook::Pwd %} $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| let now = (date now | format date '%s' | into int) let elapsed = $now - $env.__zoxide_entered_at if $elapsed >= $env.__zoxide_rest_threshold and ($env.__zoxide_current_dir | is-not-empty) { $env.__zoxide_last_rested = $env.__zoxide_current_dir } $env.__zoxide_entered_at = $now $env.__zoxide_current_dir = $dir ^zoxide add -- $dir } }) } {%- endif %} # Rest tracking for z --. $env.__zoxide_rest_threshold = (try { $env._ZO_REST_THRESHOLD | into int } catch { 5 }) $env.__zoxide_entered_at = (date now | format date '%s' | into int) $env.__zoxide_current_dir = $env.PWD $env.__zoxide_last_rested = '' } {%- endif %} {{ section }} # When using zoxide with --no-cmd, alias these internal functions as desired. # # Jump to a directory using only keywords. def --env --wrapped __zoxide_z [...rest: string] { let path = match $rest { [] => {'~'}, [ '-' ] => {'-'}, [ $arg ] if ($arg | path expand | path type) == 'dir' => {$arg} [ '--' ] => { if $env.__zoxide_last_rested != '' { $env.__zoxide_last_rested } else { error make {msg: "zoxide: no rested directory found"} } } _ => { ^zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n" } } cd $path {%- if echo %} echo $env.PWD {%- endif %} } # Jump to a directory using interactive search. def --env --wrapped __zoxide_zi [...rest:string] { cd $'(^zoxide query --interactive -- ...$rest | str trim -r -c "\n")' {%- if echo %} echo $env.PWD {%- endif %} } {{ section }} # Commands for zoxide. Disable these using --no-cmd. # {%- match cmd %} {%- when Some with (cmd) %} alias {{cmd}} = __zoxide_z alias {{cmd}}i = __zoxide_zi {%- when None %} {{ not_configured }} {%- endmatch %} {{ section }} # 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+.