diff --git a/CHANGELOG.md b/CHANGELOG.md index a952e0b..c8fd903 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,9 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Nushell: `z` now supports Space-Tab completions. + ### Fixed -- Bash/Zsh: fix `z` failing on Cygwin/MSYS2 due to `cygpath` being passed a bad string. +- Bash/Zsh: `z` failing on Cygwin/MSYS2 due to `cygpath` being passed a bad string. - Nushell: `z` now handles relative paths through symlinked directories. ## [0.10.0] - 2026-07-04 diff --git a/README.md b/README.md index 6d9af91..8b169ab 100644 --- a/README.md +++ b/README.md @@ -268,7 +268,7 @@ zoxide can be installed in 4 easy steps: > ``` > > **Note:** - > zoxide only supports Nushell v0.89.0+. + > zoxide only supports Nushell v0.110.0+. diff --git a/man/man1/zoxide-init.1 b/man/man1/zoxide-init.1 index ebf1ed1..26b7b0c 100644 --- a/man/man1/zoxide-init.1 +++ b/man/man1/zoxide-init.1 @@ -45,7 +45,7 @@ Now, add this to the \fBend\fR of your config file (find it by running \fBsource ~/.zoxide.nu\fR .fi .sp -Note: zoxide only supports Nushell v0.89.0+. +Note: zoxide only supports Nushell v0.110.0+. .TP .B powershell Add this to the \fBend\fR of your config file (find it by running \fBecho diff --git a/templates/nushell.txt b/templates/nushell.txt index e2aa661..977244f 100644 --- a/templates/nushell.txt +++ b/templates/nushell.txt @@ -14,14 +14,9 @@ # 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 } } + $env.config.hooks.pre_prompt + | any { get __zoxide_hook? | default false } ) if not $__zoxide_hooked { $env.config.hooks.pre_prompt = ($env.config.hooks.pre_prompt | append { @@ -30,18 +25,12 @@ export-env { }) } {%- 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 } } + $env.config.hooks.env_change.PWD? | default [] + | any { get __zoxide_hook? | default false } ) if not $__zoxide_hooked { - $env.config.hooks.env_change.PWD = ($env.config.hooks.env_change.PWD | append { + $env.config.hooks.env_change.PWD = ($env.config.hooks.env_change.PWD? | append { __zoxide_hook: true, code: {|_, dir| ^zoxide add -- $dir} }) @@ -51,12 +40,33 @@ export-env { {%- endif %} +{{ section }} +# Completion for __zoxide_z +# + +def "nu-complete __zoxide_z" [context: string] { + let ast = ast --flatten $context | skip 1 # skip the command name + + # If the user has typed a space after the first argument, use the custom + # completer. If not, use the built-in directory completion. + if ($ast | is-empty) { return null } + if $ast.0.span.end >= ($context | str length) { return null } + + ^zoxide query --exclude $env.PWD --interactive -- ...$ast.content + | if $in starts-with $"($nu.home-dir)(char psep)" { str replace $nu.home-dir "~" } else {} + | [{ + display_override: $in, + value: ($in | debug --raw-value), + span: { start: ($ast | first).span.start, end: ($ast | last).span.end } + }] +} + {{ section }} # 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] { +export def --env --wrapped __zoxide_z [...rest: directory@"nu-complete __zoxide_z"] { match $rest { [] => { cd ~ }, [ '-' ] => { cd - }, @@ -104,4 +114,4 @@ export alias {{cmd}}i = __zoxide_zi # # source ~/.zoxide.nu # -# Note: zoxide only supports Nushell v0.89.0+. +# Note: zoxide only supports Nushell v0.110.0+.