zoxide icon indicating copy to clipboard operation
zoxide copied to clipboard

Case-sensitivity issues with zoxide database?

Open jesseleite opened this issue 4 months ago • 8 comments

I'm using MacOS and have a ~/Code directory, and am finding inconsistent results when trying to change directory using z co vs z code...

CleanShot 2024-02-29 at 21 23 29

But then if I zoxide edit to look at database, I see it's database them as SEPARATE folders, when only one folder with this name exists?

CleanShot 2024-02-29 at 21 33 45

Is there a way to prevent zoxide from doing this?

Note: I'm coming from rupa/z, where the only thing that gets indexed is ~/Code (with capital C), therefore both z co and z code both bring me to ~/Code (with capital C), as I'd expect.

jesseleite avatar Mar 01 '24 02:03 jesseleite

@jesseleite Just giving my 2 cents here. Apple FS is case insensitive by default. Zoxide uses by default pwd -L for path resolving and this returns the lower case one. You can set _ZO_RESOLVE_SYMLINKS=1 that uses pwd -P which after resolving the symlink, get you to the path with the case it was created. If you don't really need to store the link instead of the real path, setting this var env solves it.

dalton-oliveira avatar Mar 12 '24 18:03 dalton-oliveira

@dalton-oliveira Interesting. That works as far as only storing the proper path, but this is weird...

So if I z code once, it'll take me to lowercase ~/code.

But if I z code a second time from that folder, it'll then take me to Code (with capital 'C' as it exists on my system)?

https://github.com/ajeetdsouza/zoxide/assets/5187394/e039b3c2-69ad-4ca4-a358-4b04ee223932

jesseleite avatar Mar 28 '24 00:03 jesseleite

This behavior is due to, after you change to code dir and then z code again, it will attempt to find an existing dir within the path you are. If not exists, it queries the db. The db had the path symlink resolved with the capital letter C. That's why you jump to the same. I think it makes sense to first try the "built in way" and on no success query the db, because querying the db is slower. Here's the relevant code I found:

The -d "$1" checks the 1st arg is a directory. If it's, it jumps in and call the hook. The 2nd z code goes to the else part.

https://github.com/ajeetdsouza/zoxide/blob/94d3cba60e24139319c7d370d796967c607b54ef/templates/zsh.txt#L55-L67

dalton-oliveira avatar Mar 28 '24 12:03 dalton-oliveira

@dalton-oliveira Oh interesting! Are you suggesting a potential change under the hood? Or something I'm supposed to do as an end user?

I really want to use zoxide though for two reasons: 1) I really like zoxide edit for viewing the db, and 2) I'm playing with @joshmedeski's awesome sesh package which relies on zoxide.

Thing is though, I'm coming from rupa/z which handles this directory case-sensitivity stuff on MacOS just fine, in that it never puts me in a directory in lowercase, when the directory exists on my system with uppercase characters.

jesseleite avatar Mar 29 '24 20:03 jesseleite

Just my two cents about this specific problem @jesseleite, you might want to change your directory to lowercase "code" 😉

joshmedeski avatar Mar 29 '24 23:03 joshmedeski

@joshmedeski That's a workaround, not a solution. MacOS allows us to capitalize folder names :D

jesseleite avatar Mar 29 '24 23:03 jesseleite

@jesseleite Can you test ? You'll need cargo for building. Then make sure you are in a zsh that zoxide is not enabled (just comment the init command on .zshrc. Then run

export _ZO_RESOLVE_SYMLINKS=1
cargo build && eval "$(./target/debug/zoxide init zsh --cmd z)"

dalton-oliveira avatar Apr 01 '24 19:04 dalton-oliveira

@dalton-oliveira Just built and tested your PR, works perfect 😍

jesseleite avatar Apr 01 '24 20:04 jesseleite