1
Fork 0
mirror of https://github.com/thegeneralist01/config.git synced 2026-03-10 02:30:29 +01:00

shell: fix zoxide cd

This commit is contained in:
TheGeneralist 2026-01-30 14:47:24 +01:00
parent 65ad4a6d6b
commit b5d2518afd
Signed by: thegeneralist01
SSH key fingerprint: SHA256:pp9qddbCNmVNoSjevdvQvM5z0DHN7LTa8qBMbcMq/R4

View file

@ -1,47 +1,54 @@
{ lib, pkgs, ... }: let { lib, pkgs, ... }:
let
inherit (lib) getExe; inherit (lib) getExe;
zoxide = getExe pkgs.zoxide; zoxide = getExe pkgs.zoxide;
in { in
home-manager.sharedModules = [{ {
programs.zoxide = { home-manager.sharedModules = [
enable = true; {
options = [ "--cmd cd" ]; programs.zoxide = {
enableNushellIntegration = false; enable = true;
}; options = [ "--cmd cd" ];
enableNushellIntegration = false;
};
programs.nushell.extraConfig = /* nu */ '' programs.nushell.extraConfig = # nu
# Zoxide integration with full path ''
$env.config = ($env.config? | default {}) # Zoxide integration with full path
$env.config.hooks = ($env.config.hooks? | default {}) $env.config = ($env.config? | default {})
$env.config.hooks.env_change = ($env.config.hooks.env_change? | default {}) $env.config.hooks = ($env.config.hooks? | default {})
$env.config.hooks.env_change.PWD = ($env.config.hooks.env_change.PWD? | 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 } }) let __zoxide_hooked = ($env.config.hooks.env_change.PWD | any { try { get __zoxide_hook } catch { false } })
if not $__zoxide_hooked { 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, __zoxide_hook: true,
code: {|_, dir| ${zoxide} add -- $dir} code: {|_, dir| ${zoxide} add -- $dir}
}) })
} }
def --env __zoxide_z [...rest: string] { def --env __zoxide_z [...rest: string] {
let path = if ($rest | length) == 0 { let path = if ($rest | length) == 0 {
$env.HOME $env.HOME
} else if ($rest | length) == 1 and ($rest.0 == "-") { } else if ($rest | length) == 1 and ($rest.0 == "-") {
$env.OLDPWD $env.OLDPWD
} else { } else if ($rest | length) == 1 and (($rest.0 | path expand) | path exists) {
${zoxide} query --exclude (pwd) -- ...$rest | str trim -r -c (char newline) $rest.0
} } else {
cd $path ${zoxide} query --exclude (pwd) -- ...$rest | str trim -r -c (char newline)
} }
cd $path
}
def --env __zoxide_zi [...rest: string] { def --env __zoxide_zi [...rest: string] {
let path = ${zoxide} query --interactive -- ...$rest | str trim -r -c (char newline) let path = ${zoxide} query --interactive -- ...$rest | str trim -r -c (char newline)
cd $path cd $path
} }
alias cd = __zoxide_z alias cd = __zoxide_z
alias cdi = __zoxide_zi alias cdi = __zoxide_zi
''; '';
}]; }
];
} }