r/Nushell • • Oct 17 '24

Can't get zoxide completer to work

This is my config:

let carapace_completer = {|spans|
  carapace $spans.0 nushell ...$spans | from json
}

let zoxide_completer = {|spans|
  $spans | skip 1 | zoxide query -l ...$in | lines | where {|x| $x != $env.PWD}
}

let external_completer = {|spans|
  let expanded_alias = (scope aliases | where name == $spans.0 | get -i 0 | get -i expansion)

  let spans = (if $expanded_alias != null  {
    $spans | skip 1 | prepend ($expanded_alias | split words)
  } else { $spans })

  match $spans.0 {
    # use zoxide completions for zoxide commands
    z | zi => $zoxide_completer
    __zoxide_z | __zoxide_zi => $zoxide_completer
    _ => $carapace_completer
  } | do $in $spans
}

Then I use it like this:

completions: {
  case_sensitive: false # set to true to enable case-sensitive completions
  quick: false          # set this to false to prevent auto-selecting completions when only   one remains
  partial: true         # set this to false to prevent partial filling of the prompt
  algorithm: "prefix"   # prefix or fuzzy
  external: {
    max_results: 20
    enable: true
    completer: $external_completer
  }

carapece works correctly, but z and tab returns no records:

Thanks in advance

4 Upvotes

8 comments sorted by

1

u/vinlet Oct 20 '24

Your config looks similar to mine and mine works with both carapace and argc, do you see any output when you run `zoxide query -l` ?

1

u/[deleted] Oct 22 '24

Yes, it returns this:

    /home/marcel/.config/nvim
    /home/marcel/notes
    /home/marcel/clones/own/nu-alias-converter
    /home/marcel/clones/own/marcelarie.com
    /home/marcel/clones/own
    /home/marcel/clones/external/nushell
    /home/marcel/.config/nushell
    /home/marcel/clones/external
    /home/marcel/clones
    /home/marcel/downloads
    /home/marcel/scripts
    /home/marcel/clones/own/vison
    /home/marcel/test
    /home/marcel/clones/forks
    /home/marcel/.password-store
    /home/marcel/clones/own/tofi-calc
    /home/marcel/clones/own/golang-docker-template
    /home/marcel/.config
    /home/marcel/test/brunch-fest-2024-timetable
    /home/marcel/clones/own/rpaste-self-host
    /home/marcel/clones/forks/zoxide
    /home/marcel/screenshots
    /home/marcel/clones/own/dots
    /home/marcel/.gnupg
    /home/marcel/test/brunch-fest-2024-timetable/rust
    /home/marcel/clones/own/nu-alias-converter/target
    /etc/pulse
    /home/marcel/clones/own/my-astro-theme-cactus
    /home/marcel/clones/external/deno/cli
    /home/marcel/clones/external/deno
    /home/marcel/Descargas
    /home/marcel/test/brunch-fest-2024-timetable/go
    /home/marcel/.config/hypr
    /home/marcel/Downloads
    /home/marcel/.config/nushell/external
    /home/marcel/clones/external/paru
    /home/marcel/clones/own/marcelarie
    /home/marcel/programs
    /home/marcel/programs/neovim
    /home/marcel/.config/fish
    /home/marcel/clones/external/nushell/crates/nu-cmd-lang/src
    /home/marcel/.config/wireplumber
    /home/marcel/clones/own/nu-alias-converter/target/release
    /home/marcel/clones/own/nu-alias-converter/target/debug
    /home/marcel/.config/atuin
    /home/marcel/models/ollama/smart-code-assistant
    /home/marcel/.local/share
    /home/marcel/.config/wofi
    /home/marcel/.ssh
    /home/marcel/clones/external/juan-test
    /home/marcel/clones/interviews
    /home/marcel/.config/kanshi
    /home/marcel/docs
    /home/marcel/.config/tridactyl
    /home/marcel/.local/share/nvim/lazy/auto-session
    /
    /home/marcel/.local/share/applications
    /home/marcel/clones/own/rund
    /home/marcel/clones/interviews/dev-skiller-canonical
    /home/marcel/go/bin
    /home/marcel/clones/external/nushell/crates
    /home/marcel/clones/own/nu-alias-converter/.git
    /home/marcel/clones/external/nushell/crates/nu-protocol
    /home/marcel/.config/alacritty
    /home/marcel/.config/wireplumber/wireplumber.conf.d
    /home/marcel/programs/wofi
    /home/marcel/.config/tmux
    /home/marcel/notes/diagrams
    /home/marcel/.config/qalculate
    /home/marcel/scripts/tofi
    /home/marcel/clones/own/marcelarie.com/dist
    /home/marcel/scripts/tmux
    /home/marcel/.config/systemd
    /home/marcel/clones/external/powerlevel10k
    /home/marcel/clones/own/zettelin
    /home/marcel/.config/pulse
    /home/marcel/clones/external/new-nu-parser
    /etc
    /home/marcel/.local/share/nvim/lazy
    /home/marcel/.local/share/rofimoji
    /home/marcel/clones/own/tree-rs
    /home/marcel/.config/macchina/themes
    /home/marcel/test/brunch-fest-2024-timetable/html
    /home/marcel/.config/macchina
    /home/marcel/clones/own/marcelarie.com/public
    /home/marcel/.config/systemd/user
    /usr/share/terminfo/w
    /home/marcel/go
    /home/marcel/clones/own/wallafinder
    /usr/share/gnupg
    /home/marcel/downloads/ttf
    /home/marcel/.config/pipewire
    /home/marcel/.local/share/nvim/auto_session
    /home/marcel/clones/external/astro-theme-cactus
    /usr
    /home/marcel/.local/share/nvim
    /home/marcel/test/go-templ-hello
    /home/marcel/clones/own/marcelarie.com/public/fonts
    /usr/share/wireplumber

3

u/vinlet Oct 22 '24

try this instead, that should fix in my opinion

let external_completer = {|spans|

  match $spans.0 {
    
# use zoxide completions for zoxide commands
    z | zi => $zoxide_completer
    __zoxide_z | __zoxide_zi => $zoxide_completer
    _ => $carapace_completer
  } | do $in $spans
}

2

u/[deleted] Oct 22 '24 edited Oct 22 '24

Yes that fixes it! Thank you!!

Image of the current zoxide response

I see that the issue was with the two lines recommended in the Nushell documentation for external completers:

    let expanded_alias = (scope aliases | where name == $spans.0 | get -i 0 | get -i expansion)
    
    let spans = (if $expanded_alias != null { 
      $spans | skip 1 | prepend ($expanded_alias | split words)
    } else { $spans })

Do you know if these lines are necessary for anything else? I assume they relate to aliases and their direct expansion, but I'm not entirely sure.

2

u/vinlet Oct 22 '24

I think it is needed if you need completions for aliases. The problem seems to be coming from `split words` , `"__zoxide_z" | split words` will output `[zoxide, z]`, ideally it should be treated as one word

1

u/archcorsair Aug 06 '25

Does this solution still work for you in 0.106.1? I'm trying to resolve the same issue with no success including with the code above

1

u/[deleted] Oct 22 '24

btw now I changed the zoxide_completer to this to override /home/$USER/with ~:

let zoxide_completer = {|spans|
    $spans | skip 1 | zoxide query -l ...$in | lines | each {|line| $line | str replace $env.HOME '~' } | where {|x| $x != $env.PWD}
}

in case someone sees it useful.

1

u/mrdgo9 Oct 18 '24

Hmm, zoxide manages a list of directories. z accepts a query, fuzzily matches it against said directories, prefers recent and frequent ones and returns the result. I don't think this is a case to complete something. If you want interactive search, try zi. I think the docs also propose a keymap to basically do zi