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

Case-sensitivity issues with zoxide database? #740

Open
jesseleite opened this issue Mar 1, 2024 · 8 comments · May be fixed by #777
Open

Case-sensitivity issues with zoxide database? #740

jesseleite opened this issue Mar 1, 2024 · 8 comments · May be fixed by #777

Comments

@jesseleite
Copy link

jesseleite commented Mar 1, 2024

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.

@dalton-oliveira
Copy link

@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.

@jesseleite
Copy link
Author

@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)?

CleanShot.2024-03-27.at.20.53.37.mp4

@dalton-oliveira
Copy link

dalton-oliveira commented Mar 28, 2024

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.

zoxide/templates/zsh.txt

Lines 55 to 67 in 94d3cba

# Jump to a directory using only keywords.
function __zoxide_z() {
# shellcheck disable=SC2199
if [[ "$#" -eq 0 ]]; then
__zoxide_cd ~
elif [[ "$#" -eq 1 ]] && { [[ -d "$1" ]] || [[ "$1" = '-' ]] || [[ "$1" =~ ^[-+][0-9]$ ]]; }; then
__zoxide_cd "$1"
else
\builtin local result
# shellcheck disable=SC2312
result="$(\command zoxide query --exclude "$(__zoxide_pwd)" -- "$@")" && __zoxide_cd "${result}"
fi
}

@jesseleite
Copy link
Author

@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.

@joshmedeski
Copy link
Contributor

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

@jesseleite
Copy link
Author

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

@dalton-oliveira dalton-oliveira linked a pull request Apr 1, 2024 that will close this issue
@dalton-oliveira
Copy link

@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)"

@jesseleite
Copy link
Author

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

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

Successfully merging a pull request may close this issue.

3 participants