Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial match high priority nested path over exact direct descendent (edge-case) #825

Closed
qgates opened this issue May 22, 2024 · 5 comments

Comments

@qgates
Copy link

qgates commented May 22, 2024

In ~ I have 2 folders:

~/go
~/dev/srv/api-go

The latter is in z's db with a high priority (80+).

  • If I type z go from anywhere I end up in ~/dev/srv/api-go (wanted behaviour)
  • But when I type z go from ~ it takes me to ~/go (unwanted behaviour)

Can this be fixed without excluding ~/go entirely? So I could still type z ./go or z ~/go to get there, but in all other cases z go matches ~/dev/srv/api-go.

I'll admit this is an edge case but it's been chafing with me lately. Perhaps a negative score in zoxide edit would indicate such directories?

Apologies in advance if I've missed anything obvious 😉

@ajeetdsouza
Copy link
Owner

z behaves first like a cd command, and then like a "jump" command. This is so that you don't have to build muscle memory for two commands (should I cd into this directory, or use z?)

The only way to solve this particular case is to use a query that will not match a local directory. Here's some alternatives:

  • z api
  • z / go
  • z a go

@qgates
Copy link
Author

qgates commented May 22, 2024

Thanks for your response. I am aware of the workarounds, but the example I gave is one of many. The issue - for me at least - is that although z is designed to replace cd, it isn't cd on account of its additional fuzzy matching db capability.

z can fuzzy match or exact match, but the behaviour is dependent upon which directory a user is already in. That's confusing for the user: will z go change to an immediate subdirectory called go or will it fuzzy match from its database?

What I'm suggesting is to make that semantically clear, or to provide that as an option. It makes more sense to me at least. Operands resulting in a physical pathspec behave like cd and in all other cases fuzzy matching from the database.

@ajeetdsouza
Copy link
Owner

It's easy enough to implement - zoxide is designed with scriptability in mind. What you're asking for can be achieved with a simple one line function:

function z() { cd "$(zoxide query -- "$@")" }

@qgates
Copy link
Author

qgates commented May 23, 2024

Wasn't aware of that - thanks. However, that's not quite what I'm looking for. The above only works with parameters that match entries in the db, and doesn't work in situations where I want to do a straight cd with a pathspec eg:

z ./go or z /home/user/go

Sorry to trouble you further, but is it straightforward to achieve that? So if I'm in ~ and I type z go it matches from the db, but only does a cd when a pathspec is provided ie. z ./go?

Appreciate for your help 🙂

@ajeetdsouza
Copy link
Owner

As far as Linux is concerned, cd foo is identical to cd ./foo. Both are relative paths.

You could certainly write a custom script that only tries to manually cd if the directory contains a / in it, and falls back to zoxide otherwise - should solve your problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants