ajeetdsouza / zoxide

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

Improve default Zsh completion for z #513

Open gi1242 opened 1 year ago

gi1242 commented 1 year ago

By default if I type z <Tab>, it shows me local directories twice.

Moreover, if I have a local directory called foo, then z o<Tab> shows nothing; but cd o<Tab> shows foo. (Also z f<Tab> shows foo twice).

This makes local directory completion worse than that of cd.

It can be fixed very easily: in __zoxide_z_complete, change

files -/

to

_cd

This will make the first argument of z complete local directories (exaclty like cd), and leave everything else alone.

gi1242 commented 1 year ago

(Apologies; when I initially submitted my report my comment got deleted except for the first thre words. I edited my comment to include the fill report. Sorry if you got an almost blank issue report email notification.)

OrbitalHustler commented 1 year ago

The change you're proposing isn't working for me. Instead of doing eval "$(zoxide init zsh)" I've pasted the output of zoxide init zsh in my zshrc and modified _files -/ to _cd, but this doesn't fix it.

I want to complete the hello_world directory by doing z hwo<TAB> but that doesn't work.

ryankask commented 1 year ago

This changes fixes the issue for me. Thanks @gi1242! @OrbitalHustler I needed to source the zoxide script after running autoload -Uz compinit

OrbitalHustler commented 1 year ago

Thanks @ryankask ! Figured out my issue, I had to put my autoload -Uz compinit first, eval the updated function next, and finish by compinit -i -u

@ajeetdsouza any chance of this being added into zoxide? do you see an issue with this fix?

nubunto commented 9 months ago

still doesn't work for me, not on my personal machine but it does work on my work one. both are MacOS, with identical config.

using z works as expected

edit: I was able to make it work by using --no-cmd and manually adding

\builtin alias cd=__zoxide_z
\builtin alias cdi=__zoxide_zi

to my config. weird. wondering if it'll work in my work box...

sevmonster commented 5 months ago

I've been doing this for the past while:

eval "${$(zoxide init zsh):s#_files -/#_cd#}"
alias cd=z