skywind3000 / z.lua

:zap: A new cd command that helps you navigate faster by learning your habits.
MIT License
3.01k stars 141 forks source link

zsh tab completion not working #124

Open cshao06 opened 3 years ago

cshao06 commented 3 years ago

I'm using zsh 5.8 (x86_64-pc-linux-gnu) and installed z.lua with the zinit plugin manager. If I understand correctly, tab completion in zsh should work out of the box. However, nothing happens when I press tab after, for example, z drive_c. z -i does give a few choices which means some paths are remembered and available.

❯ zi drive_c   
3:  2          $HOME/wine/prefix1/drive_c/
2:  8          $HOME/wine/prefix2/drive_c/
1:  20         $HOME/wine/prefix3/drive_c/

I'm suspecting some conflicts with other plugins but I only have those most popular ones such as zsh-users/zsh-completions, zsh-users/zsh-autosuggestions, zdharma/fast-syntax-highlighting and some ohmyzsh libs and plugins.

I can provide more details if necessary. Thanks!

chengzhycn commented 3 years ago

I met the same situation today when I updated to zsh 5.8. I also used oh-my-zsh and only loaded git plugin in my zshrc but the tab still didn't work in any situations. But if I removes z.lua from zshrc plugin field, the tab works well as it should. So I think the conflicts may be with the zsh 5.8 rather than the other plugins.

skywind3000 commented 3 years ago

zsh 补全代码都是别人的 PR 提供的,不是我写的,我对 zsh 本来也不熟,需要懂 zsh 的人帮看看。

twnaing commented 2 years ago

@csha06 the completion setup is done like this

$ zinit cdlist
# ...
compdef _zlua_zsh_tab_completion _zlua
# ...

to fix the completion just add the following in .zshrc (after zinit z.lua)

compdef z=_zlua

If this line include compdef to z also, workaround will not be needed.

https://github.com/skywind3000/z.lua/blob/83dfec084328dee172bd2435791d7c62a82ef621/z.lua#L2264

(like this).

compdef _zlua_zsh_tab_completion _zlua z 2> /dev/null

I am not an expert in ZSH. Just my finding.

TL;DR:

  1. setopt completealiases prevents compdef _zlua working for z. Adding compdef z=_zlua in .zshrc works.
  2. If you do not need the setopt completealiases then, unsetopt completealiases will fix the issue.

Related

skywind3000 commented 2 years ago

thanks @twnaing

included in : https://github.com/skywind3000/z.lua/commit/0992ebf9f1f6cdaa114e65d3aa76bfb1bd9a6fd4