From 32ed3ec28a50122c55b11f058cde36dee2130916 Mon Sep 17 00:00:00 2001 From: Juhan280 Date: Tue, 4 Nov 2025 13:15:25 +0600 Subject: [PATCH 01/14] Add nushell completion for __zoxide_z --- templates/nushell.txt | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/templates/nushell.txt b/templates/nushell.txt index 4153b39..dbd09e6 100644 --- a/templates/nushell.txt +++ b/templates/nushell.txt @@ -3,6 +3,8 @@ # Code generated by zoxide. DO NOT EDIT. +const homedir = if $nu.home-dir? != null { $nu.home-dir } else { $nu.home-path } + {{ section }} # Hook configuration for zoxide. # @@ -51,12 +53,42 @@ export-env { {%- endif %} +{{ section }} +# Completion for __zoxide_z +# + +def "nu-complete __zoxide_z" [context: string] { + let ast = ast --flatten $context | skip 1 + + # 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 } + + let completions = ^zoxide query --exclude $env.PWD --list -- ...$ast.content + | lines | each { + if $in starts-with $"($homedir)(char psep)" { + str replace $homedir "~" + } else {} + } | wrap value + | insert span { start: ($ast | first).span.start, end: ($ast | last).span.end } + + { + options: { + sort: false, + case_sensitive: false, + completion_algorithm: "substring", + } + completions: $completions, + } +} + {{ 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] { +export def --env --wrapped __zoxide_z [...rest: directory@"nu-complete __zoxide_z"] { let path = match $rest { [] => {'~'}, [ '-' ] => {'-'}, @@ -72,7 +104,7 @@ def --env --wrapped __zoxide_z [...rest: string] { } # Jump to a directory using interactive search. -def --env --wrapped __zoxide_zi [...rest:string] { +export def --env --wrapped __zoxide_zi [...rest: string] { cd $'(^zoxide query --interactive -- ...$rest | str trim -r -c "\n")' {%- if echo %} echo $env.PWD @@ -86,8 +118,8 @@ def --env --wrapped __zoxide_zi [...rest:string] { {%- match cmd %} {%- when Some with (cmd) %} -alias {{cmd}} = __zoxide_z -alias {{cmd}}i = __zoxide_zi +export alias {{cmd}} = __zoxide_z +export alias {{cmd}}i = __zoxide_zi {%- when None %} From bdedc2a813b37dc5abbd7159247df0bc01b0f123 Mon Sep 17 00:00:00 2001 From: Juhan280 Date: Thu, 12 Feb 2026 17:08:30 +0600 Subject: [PATCH 02/14] Wrap nushell integration script in a module This prevents the completion command "nu-complete __zoxide_z" from polluting the command namespace. --- templates/nushell.txt | 233 ++++++++++++++++++++++-------------------- 1 file changed, 121 insertions(+), 112 deletions(-) diff --git a/templates/nushell.txt b/templates/nushell.txt index dbd09e6..e3b45f4 100644 --- a/templates/nushell.txt +++ b/templates/nushell.txt @@ -1,133 +1,142 @@ -{%- let section = "# =============================================================================\n#" -%} +{%- let section = "# =============================================================================" -%} {%- let not_configured = "# -- not configured --" -%} # Code generated by zoxide. DO NOT EDIT. -const homedir = if $nu.home-dir? != null { $nu.home-dir } else { $nu.home-path } +module zoxide_integration { + const homedir = if $nu.home-dir? != null { $nu.home-dir } else { $nu.home-path } -{{ section }} -# Hook configuration for zoxide. -# + {{ section }} + # + # Hook configuration for zoxide. + # -{% if hook == InitHook::None -%} -{{ not_configured }} + {% 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: {|| ^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| ^zoxide add -- $dir} - }) - } -{%- endif %} -} - -{%- endif %} - -{{ section }} -# Completion for __zoxide_z -# - -def "nu-complete __zoxide_z" [context: string] { - let ast = ast --flatten $context | skip 1 - - # 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 } - - let completions = ^zoxide query --exclude $env.PWD --list -- ...$ast.content - | lines | each { - if $in starts-with $"($homedir)(char psep)" { - str replace $homedir "~" - } else {} - } | wrap value - | insert span { start: ($ast | first).span.start, end: ($ast | last).span.end } - - { - options: { - sort: false, - case_sensitive: false, - completion_algorithm: "substring", + {%- 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: {|| ^zoxide add -- $env.PWD} + }) } - completions: $completions, + {%- 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| ^zoxide add -- $dir} + }) + } + {%- endif %} } -} -{{ section }} -# When using zoxide with --no-cmd, alias these internal functions as desired. -# + {%- endif %} -# Jump to a directory using only keywords. -export def --env --wrapped __zoxide_z [...rest: directory@"nu-complete __zoxide_z"] { - let path = match $rest { - [] => {'~'}, - [ '-' ] => {'-'}, - [ $arg ] if ($arg | path expand | path type) == 'dir' => {$arg} - _ => { - ^zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n" + {{ section }} + # + # Completion for __zoxide_z + # + + def "nu-complete __zoxide_z" [context: string] { + let ast = ast --flatten $context | skip 1 + + # 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 } + + let completions = ^zoxide query --exclude $env.PWD --list -- ...$ast.content + | lines | each { + if $in starts-with $"($homedir)(char psep)" { + str replace $homedir "~" + } else {} + } | wrap value + | insert span { start: ($ast | first).span.start, end: ($ast | last).span.end } + + { + options: { + sort: false, + case_sensitive: false, + completion_algorithm: "substring", + } + completions: $completions, } } - cd $path -{%- if echo %} - echo $env.PWD -{%- endif %} + + {{ 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@"nu-complete __zoxide_z"] { + 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 + {%- if echo %} + echo $env.PWD + {%- endif %} + } + + # 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")' + {%- if echo %} + echo $env.PWD + {%- endif %} + } + + {{ section }} + # + # Commands for zoxide. Disable these using --no-cmd. + # + + {%- match cmd %} + {%- when Some with (cmd) %} + + export alias {{cmd}} = __zoxide_z + export alias {{cmd}}i = __zoxide_zi + + {%- when None %} + + {{ not_configured }} + + {%- endmatch %} } -# 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")' -{%- if echo %} - echo $env.PWD -{%- endif %} -} +export use zoxide_integration * {{ section }} -# Commands for zoxide. Disable these using --no-cmd. # - -{%- match cmd %} -{%- when Some with (cmd) %} - -export alias {{cmd}} = __zoxide_z -export 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 From 79f5f6671b8ff4a9ac2158b8b8ee3246386d1b09 Mon Sep 17 00:00:00 2001 From: Juhan280 Date: Thu, 12 Feb 2026 19:15:37 +0600 Subject: [PATCH 03/14] update minimum nushell version 0.106.0 --- README.md | 2 +- templates/nushell.txt | 26 +++++--------------------- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index b397f82..1a354b0 100644 --- a/README.md +++ b/README.md @@ -257,7 +257,7 @@ zoxide can be installed in 4 easy steps: > ``` > > **Note** - > zoxide only supports Nushell v0.89.0+. + > zoxide only supports Nushell v0.106.0+. diff --git a/templates/nushell.txt b/templates/nushell.txt index e3b45f4..5a0d330 100644 --- a/templates/nushell.txt +++ b/templates/nushell.txt @@ -4,6 +4,7 @@ # Code generated by zoxide. DO NOT EDIT. module zoxide_integration { + # From version 0.110.0, $nu.home-path has been renamed to $nu.home-dir const homedir = if $nu.home-dir? != null { $nu.home-dir } else { $nu.home-path } {{ section }} @@ -18,15 +19,7 @@ module zoxide_integration { # 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 } } - ) + let __zoxide_hooked = $env.config.hooks.pre_prompt | any { get __zoxide_hook? } if not $__zoxide_hooked { $env.config.hooks.pre_prompt = ($env.config.hooks.pre_prompt | append { __zoxide_hook: true, @@ -34,18 +27,9 @@ module zoxide_integration { }) } {%- 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 } } - ) + let __zoxide_hooked = $env.config.hooks.env_change.PWD? | default [] | any { get __zoxide_hook? } 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} }) @@ -146,4 +130,4 @@ export use zoxide_integration * # # source ~/.zoxide.nu # -# Note: zoxide only supports Nushell v0.89.0+. +# Note: zoxide only supports Nushell v0.106.0+. From 9ae8519506a2bb123cfb9ab48b13136236a57731 Mon Sep 17 00:00:00 2001 From: Juhan280 Date: Thu, 12 Feb 2026 20:09:10 +0600 Subject: [PATCH 04/14] always escape the paths --- templates/nushell.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/nushell.txt b/templates/nushell.txt index 5a0d330..cefa049 100644 --- a/templates/nushell.txt +++ b/templates/nushell.txt @@ -56,7 +56,7 @@ module zoxide_integration { | lines | each { if $in starts-with $"($homedir)(char psep)" { str replace $homedir "~" - } else {} + } else {} | debug --raw-value } | wrap value | insert span { start: ($ast | first).span.start, end: ($ast | last).span.end } From b106d384e7f21e4b94c8c9cd0afa400a99c9efa6 Mon Sep 17 00:00:00 2001 From: Juhan280 Date: Fri, 13 Feb 2026 17:48:16 +0600 Subject: [PATCH 05/14] disble filtering --- templates/nushell.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/nushell.txt b/templates/nushell.txt index cefa049..4ea1ad6 100644 --- a/templates/nushell.txt +++ b/templates/nushell.txt @@ -63,6 +63,7 @@ module zoxide_integration { { options: { sort: false, + filter: false, case_sensitive: false, completion_algorithm: "substring", } From b8844cd373ffd92aa022e7d1b08f900d067a9bd7 Mon Sep 17 00:00:00 2001 From: Juhan280 Date: Thu, 19 Feb 2026 01:48:13 +0600 Subject: [PATCH 06/14] make closures in `any` command return boolean --- templates/nushell.txt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/templates/nushell.txt b/templates/nushell.txt index 4ea1ad6..14782a0 100644 --- a/templates/nushell.txt +++ b/templates/nushell.txt @@ -19,7 +19,10 @@ module zoxide_integration { # Initialize hook to add new entries to the database. export-env { {%- if hook == InitHook::Prompt %} - let __zoxide_hooked = $env.config.hooks.pre_prompt | any { get __zoxide_hook? } + let __zoxide_hooked = ( + $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 { __zoxide_hook: true, @@ -27,7 +30,10 @@ module zoxide_integration { }) } {%- else if hook == InitHook::Pwd %} - let __zoxide_hooked = $env.config.hooks.env_change.PWD? | default [] | any { get __zoxide_hook? } + let __zoxide_hooked = ( + $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 { __zoxide_hook: true, From be220c9542a793562bac873894ee5a57c604f394 Mon Sep 17 00:00:00 2001 From: Juhan280 Date: Sat, 21 Feb 2026 02:28:23 +0600 Subject: [PATCH 07/14] use display_override --- templates/nushell.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/templates/nushell.txt b/templates/nushell.txt index 14782a0..31f19de 100644 --- a/templates/nushell.txt +++ b/templates/nushell.txt @@ -62,8 +62,9 @@ module zoxide_integration { | lines | each { if $in starts-with $"($homedir)(char psep)" { str replace $homedir "~" - } else {} | debug --raw-value - } | wrap value + } else {} + } | wrap display_override + | insert value { get display_override | debug --raw-value } | insert span { start: ($ast | first).span.start, end: ($ast | last).span.end } { From 5f0e47c5ee3ab90aaf5ada3f391ae219ffe1d4d2 Mon Sep 17 00:00:00 2001 From: Juhan280 Date: Thu, 2 Jul 2026 02:15:12 +0600 Subject: [PATCH 08/14] use fzf based sorting instead of nushell buitin --- templates/nushell.txt | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/templates/nushell.txt b/templates/nushell.txt index 31f19de..f4d3d30 100644 --- a/templates/nushell.txt +++ b/templates/nushell.txt @@ -51,31 +51,20 @@ module zoxide_integration { # def "nu-complete __zoxide_z" [context: string] { - let ast = ast --flatten $context | skip 1 + 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 } - let completions = ^zoxide query --exclude $env.PWD --list -- ...$ast.content - | lines | each { - if $in starts-with $"($homedir)(char psep)" { - str replace $homedir "~" - } else {} - } | wrap display_override + ^zoxide query --exclude $env.PWD --interactive -- ...$ast.content + | str trim --right --char "\n" + | if $in starts-with $"($homedir)(char psep)" { str replace $homedir "~" } else {} + | wrap display_override | insert value { get display_override | debug --raw-value } | insert span { start: ($ast | first).span.start, end: ($ast | last).span.end } - - { - options: { - sort: false, - filter: false, - case_sensitive: false, - completion_algorithm: "substring", - } - completions: $completions, - } + | [$in] } {{ section }} From c29b94ad345e241b28193044ea8e61c2af419119 Mon Sep 17 00:00:00 2001 From: Juhan280 Date: Thu, 2 Jul 2026 23:04:58 +0600 Subject: [PATCH 09/14] docs: update minimum nushell version in manpage --- README.md | 2 +- man/man1/zoxide-init.1 | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4c17ade..2bc9e10 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.106.0+. + > zoxide requires Nushell v0.106.0+. A newer version is recommended for completions to work properly. diff --git a/man/man1/zoxide-init.1 b/man/man1/zoxide-init.1 index ebf1ed1..b130347 100644 --- a/man/man1/zoxide-init.1 +++ b/man/man1/zoxide-init.1 @@ -45,7 +45,8 @@ 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 requires Nushell v0.106.0 or later. A more recent version is +recommended for completions to function correctly. .TP .B powershell Add this to the \fBend\fR of your config file (find it by running \fBecho From bf43eea93bef49a883c0eb117bfee50acdda33b5 Mon Sep 17 00:00:00 2001 From: Juhan280 Date: Thu, 2 Jul 2026 23:16:43 +0600 Subject: [PATCH 10/14] docs: formatting --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2bc9e10..c572e7a 100644 --- a/README.md +++ b/README.md @@ -268,7 +268,8 @@ zoxide can be installed in 4 easy steps: > ``` > > **Note:** - > zoxide requires Nushell v0.106.0+. A newer version is recommended for completions to work properly. + > zoxide requires Nushell v0.106.0+. A newer version is recommended for + > completions to work properly. From 0212406e4d539a336eba1d2dcfcf425f1505e6ad Mon Sep 17 00:00:00 2001 From: Juhan280 Date: Tue, 14 Jul 2026 15:10:41 +0600 Subject: [PATCH 11/14] address review comments bump minimum supported nushell version to 0.110 --- README.md | 3 +-- man/man1/zoxide-init.1 | 3 +-- templates/nushell.txt | 17 +++++++---------- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index c572e7a..8b169ab 100644 --- a/README.md +++ b/README.md @@ -268,8 +268,7 @@ zoxide can be installed in 4 easy steps: > ``` > > **Note:** - > zoxide requires Nushell v0.106.0+. A newer version is recommended for - > completions to work properly. + > zoxide only supports Nushell v0.110.0+. diff --git a/man/man1/zoxide-init.1 b/man/man1/zoxide-init.1 index b130347..26b7b0c 100644 --- a/man/man1/zoxide-init.1 +++ b/man/man1/zoxide-init.1 @@ -45,8 +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 requires Nushell v0.106.0 or later. A more recent version is -recommended for completions to function correctly. +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 f4d3d30..cfeafb4 100644 --- a/templates/nushell.txt +++ b/templates/nushell.txt @@ -4,9 +4,6 @@ # Code generated by zoxide. DO NOT EDIT. module zoxide_integration { - # From version 0.110.0, $nu.home-path has been renamed to $nu.home-dir - const homedir = if $nu.home-dir? != null { $nu.home-dir } else { $nu.home-path } - {{ section }} # # Hook configuration for zoxide. @@ -59,12 +56,12 @@ module zoxide_integration { if $ast.0.span.end >= ($context | str length) { return null } ^zoxide query --exclude $env.PWD --interactive -- ...$ast.content - | str trim --right --char "\n" - | if $in starts-with $"($homedir)(char psep)" { str replace $homedir "~" } else {} - | wrap display_override - | insert value { get display_override | debug --raw-value } - | insert span { start: ($ast | first).span.start, end: ($ast | last).span.end } - | [$in] + | 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 }} @@ -127,4 +124,4 @@ export use zoxide_integration * # # source ~/.zoxide.nu # -# Note: zoxide only supports Nushell v0.106.0+. +# Note: zoxide only supports Nushell v0.110.0+. From 9e899405c582ac9c0482017c8be4c692fcb4a0d1 Mon Sep 17 00:00:00 2001 From: Juhan280 Date: Tue, 14 Jul 2026 15:28:18 +0600 Subject: [PATCH 12/14] doc: add to change log --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a952e0b..89f8b48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Nushell: `z` now supports fzf completion + ### Fixed - Bash/Zsh: fix `z` failing on Cygwin/MSYS2 due to `cygpath` being passed a bad string. From 4fa24fc5e59184c5683916aaf513fa0f61edf811 Mon Sep 17 00:00:00 2001 From: Ajeet D'Souza <98ajeet@gmail.com> Date: Tue, 14 Jul 2026 17:32:05 +0530 Subject: [PATCH 13/14] Update CHANGELOG --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89f8b48..c8fd903 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,11 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Nushell: `z` now supports fzf completion +- 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 From e846019923eaf7a0267bc61e76cb1907fec6538b Mon Sep 17 00:00:00 2001 From: Juhan280 Date: Tue, 14 Jul 2026 18:40:18 +0600 Subject: [PATCH 14/14] unwrap module --- templates/nushell.txt | 197 ++++++++++++++++++++---------------------- 1 file changed, 94 insertions(+), 103 deletions(-) diff --git a/templates/nushell.txt b/templates/nushell.txt index f835653..977244f 100644 --- a/templates/nushell.txt +++ b/templates/nushell.txt @@ -1,119 +1,110 @@ -{%- let section = "# =============================================================================" -%} +{%- let section = "# =============================================================================\n#" -%} {%- let not_configured = "# -- not configured --" -%} # Code generated by zoxide. DO NOT EDIT. -module zoxide_integration { - {{ section }} - # - # Hook configuration for zoxide. - # +{{ section }} +# Hook configuration for zoxide. +# - {% if hook == InitHook::None -%} - {{ not_configured }} +{% if hook == InitHook::None -%} +{{ not_configured }} - {%- else -%} - # Initialize hook to add new entries to the database. - export-env { - {%- if hook == InitHook::Prompt %} - let __zoxide_hooked = ( - $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 { - __zoxide_hook: true, - code: {|| ^zoxide add -- $env.PWD} - }) - } - {%- else if hook == InitHook::Pwd %} - let __zoxide_hooked = ( - $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 { - __zoxide_hook: true, - code: {|_, dir| ^zoxide add -- $dir} - }) - } - {%- endif %} +{%- else -%} +# Initialize hook to add new entries to the database. +export-env { +{%- if hook == InitHook::Prompt %} + let __zoxide_hooked = ( + $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 { + __zoxide_hook: true, + code: {|| ^zoxide add -- $env.PWD} + }) } - - {%- 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 } - }] +{%- else if hook == InitHook::Pwd %} + let __zoxide_hooked = ( + $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 { + __zoxide_hook: true, + code: {|_, dir| ^zoxide add -- $dir} + }) } - - {{ 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@"nu-complete __zoxide_z"] { - let path = match $rest { - [] => { cd ~ }, - [ '-' ] => { cd - }, - [ $arg ] if (try { cd $arg; true } catch { false }) => {}, - _ => { - cd (^zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n") - } - } - {%- if echo %} - echo $env.PWD - {%- endif %} - } - - # 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")' - {%- if echo %} - echo $env.PWD - {%- endif %} - } - - {{ section }} - # - # Commands for zoxide. Disable these using --no-cmd. - # - - {%- match cmd %} - {%- when Some with (cmd) %} - - export alias {{cmd}} = __zoxide_z - export alias {{cmd}}i = __zoxide_zi - - {%- when None %} - - {{ not_configured }} - - {%- endmatch %} +{%- endif %} } -export use zoxide_integration * +{%- 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@"nu-complete __zoxide_z"] { + match $rest { + [] => { cd ~ }, + [ '-' ] => { cd - }, + [ $arg ] if (try { cd $arg; true } catch { false }) => {}, + _ => { + cd (^zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n") + } + } +{%- if echo %} + echo $env.PWD +{%- endif %} +} + +# 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")' +{%- if echo %} + echo $env.PWD +{%- endif %} +} + +{{ section }} +# Commands for zoxide. Disable these using --no-cmd. +# + +{%- match cmd %} +{%- when Some with (cmd) %} + +export alias {{cmd}} = __zoxide_z +export 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