ajeetdsouza / zoxide

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

Filter results to subset. Maybe `_ZO_INCLUDE_DIRS` #679

Closed theherk closed 5 months ago

theherk commented 5 months ago

I'd love to be able to call query but only return directories that contain .git/ for example. Since I can already list those quite simply, it seems adding an "include" feature would allow me to select from the subset I seek.

Or is there another way to do this currently?

I want to search for all directories that are git roots using the scores as given in the zoxide data.


Worth noting, a simple workaround is to add something like | rg -Fxf ~/.projects, but that only works with query -l not query -i.

ajeetdsouza commented 5 months ago

zoxide query -l "/.git/" would give you all entries within directories named .git, but not the .git directories themselves.

zoxide query -l "/.git" "/" would give you all entries within .git as well as .git itself.

theherk commented 5 months ago

Appreciate the follow up, but that doesn't seem to address what I seek; I was probably unclear. Imagine a list of directories:

From that list, I only want to find "a". That is the root of a git directory. But your solution allows me to find "a/.git", I believe. That is of course, similarly useful, but the trouble is "a" is the actual directory I need to find, and that has a correctly incremented score, as it is the directory I use.

What I'm doing at the moment is building a list of these project roots here with fd -HI -d 6 "^\.git\$" $P | xargs dirname 2>/dev/null, then using this as a filter for the response from zoxide query -l, but I can't use it interactively.