ajeetdsouza / zoxide

A smarter cd command. Supports all major shells.
MIT License
20.54k stars 523 forks source link

Fuzzy match / search feature doesn't seem to work until I explicitly go there first #696

Closed allquixotic closed 5 months ago

allquixotic commented 5 months ago

MacOS 14.3.1 arm64 (Apple Silicon) Shell = zsh (MacOS builtin version 5.9)

I installed zoxide with cargo install zoxide using the latest stable rustc from rustup. I installed fzf with brew install fzf.

tail -n2 ~/.zshrc => eval "$(zoxide init zsh)"

Terminal emulator = warp (thanks for the recommendation!)

pwd
/Users/sean
zoxide add /Users/sean/dev ### Isn't this supposed to recursively add everything in ~/dev?
cd dev/cosmos
pwd
/Users/sean/dev/cosmos
z
z cosmos ### THIS WORKS! Ok cool!
z
ls dev/langchain ### To prove it exists
CITATION.cff    MIGRATE.md  README.md   cookbook    docs        poetry.lock pyproject.toml
LICENSE     Makefile    SECURITY.md docker      libs        poetry.toml templates
z langchain 
zoxide: no match found ### WHY??? Do I have to explicitly `cd` there first before it will work? That's silly.
z dev langchain
zoxide: no match found ### It *still* doesn't work?
cd dev/langchain ### Works.

I'm not sure if this is intended behavior, but if I have to explicitly go somewhere first before z will work, rather than having it automatically search or find my directories (especially at a location where I've done a zoxide add previously), that seems to defeat most of the purpose of the tool.

Justification: I have only a few top level directories in my home directory I frequently use (~/dev, ~/Downloads, ~/Documents, etc.) but I'm constantly creating and deleting subdirectories, sub-sub-directories, etc. in those. If I can't just z langchain without first explicitly telling the tool that that directory exists, it's going to be very frustrating to use, vs. having the tool just search and find that that directory exists and cding there. At that point, I may as well use cd.

bew commented 5 months ago

It is working as intended, on hompage zoxide says:

It remembers which directories you use most frequently, so you can "jump" to them in just a few keystrokes.

There is zero auto discovery system in-place.

Now if you want to change your shell a bit to add integration points like register a path to zoxide every time you create a folder via mkdir, you can always do it 🤷

allquixotic commented 5 months ago

Thanks for the clarification. It wasn't clear to me from the docs. Maybe in the future zoxide can support some sort of directory search, where it recursively looks within the directories added to its database, for a fuzzy match.

On a modern system with an NVMe SSD and an OS with an efficient filesystem (like xfs, ext4 or zfs on Linux, or apfs on MacOS), finding a directory with a desired name - especially within a whitelisted set of folders - is an extremely fast operation.

For example, on my M2 MacBook Air:

❯ time fd -t d -1 addons
Documents/Elder Scrolls Online/live/AddOns/
fd -t d -1 addons  0.01s user 0.03s system 174% cpu 0.025 total

The filesystem automatically caches its directory entry information into RAM after you start enumerating directories once, so the subsequent operations after the first one are very fast. And the beauty is, you don't have to write any caching code to make this fast - your operating system gives you this for free.

It would be good to add this capability to zoxide. There's already rust code that can be leveraged for it in the fd-find project. Bringing it in-process within zoxide (instead of an external process) would minimize the performance impact instead of hacking together zoxide and fd using the shell.

I personally feel that a directory cache database would be unnecessary, since that's literally what the filesystem is in the first place. Filesystem walk / search operations have a bad reputation because of (1) Windows, which usually has an on-access virus scanner that vastly slows down FS operations, and (2) hard disk drives. But there are many, many deployed systems out there, especially those operated by developers who would use zoxide, that use neither an on-access scanner, nor a hard disk.

If zoxide wanted to support Windows + on-access virus scanner + complicated directory trees with decent performance, zoxide could cache its knowledge of the directory tree in a sqlite database. You can query a database index much, much faster than you can enumerate a directory tree on a boat-anchored Windows system. But on MacOS or Linux, the performance between the two options is similar.

In any case, I understand now that this is not part of the feature-set of zoxide currently.