From 17117d82edacd236eaf3634e54b650b30d5bbc06 Mon Sep 17 00:00:00 2001 From: Fredrik Robertsen Date: Wed, 1 Apr 2026 17:33:00 +0200 Subject: [PATCH] add zoxide --- dotfiles/.config/nushell/config.nu | 2 + dotfiles/.config/nushell/zoxide.nu | 70 ++++++++++++++++++++++++++++++ modules/dev/default.nix | 2 + 3 files changed, 74 insertions(+) create mode 100644 dotfiles/.config/nushell/zoxide.nu diff --git a/dotfiles/.config/nushell/config.nu b/dotfiles/.config/nushell/config.nu index 7c71ff2..eb3bf19 100644 --- a/dotfiles/.config/nushell/config.nu +++ b/dotfiles/.config/nushell/config.nu @@ -55,3 +55,5 @@ $env.config.hooks.pre_prompt = ( | load-env } ) + +source ($nu.default-config-dir | path join "zoxide.nu") diff --git a/dotfiles/.config/nushell/zoxide.nu b/dotfiles/.config/nushell/zoxide.nu new file mode 100644 index 0000000..11f08c0 --- /dev/null +++ b/dotfiles/.config/nushell/zoxide.nu @@ -0,0 +1,70 @@ +# Code generated by zoxide. DO NOT EDIT. + +# ============================================================================= +# +# Hook configuration for zoxide. +# + +# Initialize hook to add new entries to the database. +export-env { + $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} + }) + } +} + +# ============================================================================= +# +# 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} + _ => { + ^zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n" + } + } + cd $path +} + +# Jump to a directory using interactive search. +def --env --wrapped __zoxide_zi [...rest:string] { + cd $'(^zoxide query --interactive -- ...$rest | str trim -r -c "\n")' +} + +# ============================================================================= +# +# Commands for zoxide. Disable these using --no-cmd. +# + +alias z = __zoxide_z +alias zi = __zoxide_zi + +# ============================================================================= +# +# 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+. diff --git a/modules/dev/default.nix b/modules/dev/default.nix index 68bf5f4..eb449f8 100644 --- a/modules/dev/default.nix +++ b/modules/dev/default.nix @@ -28,6 +28,8 @@ programs.git.enable = true; + programs.zoxide.enable = true; + environment.sessionVariables.EDITOR = "hx"; }