nushell / nushell/nushell.github.io

Script for adding curent path to `zoxide` complete

Open
#1,823 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
258
Forks
561
Avg merge
3h 20m
Merged PRs (30d)
15

Description

I like using zoxide as a replacement for cd, so I also like having the tab complete have the current dirs in the directory in addition to the zoxide complete.

I'm not too sure in my own nushell code, so I don't want to make a pull request, but I'd like to share how I added the current dir to my zoxide complete.

let zoxide_completer = {|spans|
  let path = ($spans.1 | glob $"\(?i\)($in)*" | where {path type | $in == dir} | each {path relative-to (glob "." | first)})
  let zoxide = ($spans | skip 1 | zoxide query -l ...$in | lines | where {|x| $x != $env.PWD})
  ($zoxide | prepend $path)
}

this addition to the completer allows you to do this:

Image

The first two entries are from the current dir, the second two are from zoxide.

There are a few places this script can fail. Firstly being with the path relative-to command. It will straight up fail if the prefix can't be found. I have an immutable distro so my /home/user folder is linked to the /var/home/user folder. This makes it unreliable to use $env.PWD as this will be different from what glob returns, so I just glob . instead, lol. Also, I'm unsure if spans always return more than one element. It seems to work with no arguments, but I don't know how it works.

I'm sure there are better ways of doing this and such, but it works for me. Just wanted to share if anyone wanted to refine it and add it to the external_completers.md file.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading external_completers.md and checking how external completer examples are presented. Validate the proposed Nushell snippet, including no-argument and path-prefix cases mentioned in the issue. Done means the documented example reliably adds current-directory entries alongside zoxide completions.

Written by the indexing model from the issue text.

Assessment

Tech stack
shell
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.