From b5d2518afd8d5b3e139b9d429488f81e4216f08a Mon Sep 17 00:00:00 2001 From: TheGeneralist <180094941+thegeneralist01@users.noreply.github.com> Date: Fri, 30 Jan 2026 14:47:24 +0100 Subject: [PATCH] shell: fix zoxide cd --- modules/common/shell/zoxide.nix | 85 ++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/modules/common/shell/zoxide.nix b/modules/common/shell/zoxide.nix index 0d570aa..3e193af 100644 --- a/modules/common/shell/zoxide.nix +++ b/modules/common/shell/zoxide.nix @@ -1,47 +1,54 @@ -{ lib, pkgs, ... }: let +{ lib, pkgs, ... }: +let inherit (lib) getExe; zoxide = getExe pkgs.zoxide; -in { - home-manager.sharedModules = [{ - programs.zoxide = { - enable = true; - options = [ "--cmd cd" ]; - enableNushellIntegration = false; - }; +in +{ + home-manager.sharedModules = [ + { + programs.zoxide = { + enable = true; + options = [ "--cmd cd" ]; + enableNushellIntegration = false; + }; - programs.nushell.extraConfig = /* nu */ '' - # Zoxide integration with full path - $env.config = ($env.config? | default {}) - $env.config.hooks = ($env.config.hooks? | default {}) - $env.config.hooks.env_change = ($env.config.hooks.env_change? | default {}) - $env.config.hooks.env_change.PWD = ($env.config.hooks.env_change.PWD? | default []) + programs.nushell.extraConfig = # nu + '' + # Zoxide integration with full path + $env.config = ($env.config? | default {}) + $env.config.hooks = ($env.config.hooks? | default {}) + $env.config.hooks.env_change = ($env.config.hooks.env_change? | default {}) + $env.config.hooks.env_change.PWD = ($env.config.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} - }) - } + 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} + }) + } - def --env __zoxide_z [...rest: string] { - let path = if ($rest | length) == 0 { - $env.HOME - } else if ($rest | length) == 1 and ($rest.0 == "-") { - $env.OLDPWD - } else { - ${zoxide} query --exclude (pwd) -- ...$rest | str trim -r -c (char newline) - } - cd $path - } + def --env __zoxide_z [...rest: string] { + let path = if ($rest | length) == 0 { + $env.HOME + } else if ($rest | length) == 1 and ($rest.0 == "-") { + $env.OLDPWD + } else if ($rest | length) == 1 and (($rest.0 | path expand) | path exists) { + $rest.0 + } else { + ${zoxide} query --exclude (pwd) -- ...$rest | str trim -r -c (char newline) + } + cd $path + } - def --env __zoxide_zi [...rest: string] { - let path = ${zoxide} query --interactive -- ...$rest | str trim -r -c (char newline) - cd $path - } + def --env __zoxide_zi [...rest: string] { + let path = ${zoxide} query --interactive -- ...$rest | str trim -r -c (char newline) + cd $path + } - alias cd = __zoxide_z - alias cdi = __zoxide_zi - ''; - }]; + alias cd = __zoxide_z + alias cdi = __zoxide_zi + ''; + } + ]; }