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

Zsh completions doesn't display list of available commands when pressing tab #1565

Closed
Farid-NL opened this issue Apr 25, 2024 · 10 comments
Closed

Comments

@Farid-NL
Copy link
Contributor

Expected behaviour

  1. Pressing <TAB> should display a list of commands

    Example with gem:

    image

  2. When typing a command and there's only one possible option, it should complete the whole command

    Example with gem:

    gem ins<TAB>
    
    # completes the command
    gem install

Actual behaviour

  1. Pressing <TAB> DOES NOT display a list of commands

    Example:

    rbenv <TAB>
    
    # it shows three dots `...` for like 0.3s and then does nothing
    rbenv 
  2. When typing a command and there's only one possible option, it DOES complete the whole command

    Example:

    rbenv  ins<TAB>
    
    # completes the command
    rbenv install

Some extra info

rbenv version OS Shell Shell config
1.2.0-87-ge8b7a27 Linux x86_64 zsh zsh4humans

The only thing related to rbenv in my .zshrc is this:

eval "$(~/.rbenv/bin/rbenv init - zsh)"
@Farid-NL Farid-NL changed the title Zsh completions don't do anything when pressing tab Zsh completions doesn't display list of available commands when pressing tab Apr 25, 2024
@mislav
Copy link
Member

mislav commented Apr 29, 2024

Hi, thanks for reporting. It looks like your zsh shell has lots of customizations. Could it be that one of these customizations is affecting the behavior of typing rbenv <TAB>?

Here is what I get when I press Tab:

$ rbenv
--version           global              install             root                version             version-name        which
commands            help                local               shell               version-file        version-origin      
completions         hooks               prefix              shims               version-file-read   versions            
exec                init                rehash              uninstall           version-file-write  whence

My ~/.zshrc:

autoload -U compinit
compinit -i

autoload colors
colors

@Farid-NL
Copy link
Contributor Author

Farid-NL commented Apr 30, 2024

It does have lots of customization, mainly because of zsh4humans (sort of a zsh framework). I've never experienced issues with completions, until now.

My guess is that rbenv use the old completion system for zsh, compctl and until now I have used - rather the programs I use, handle completions with - the 'new' system (completions are managed by underscore files, like _rbenv and are in the fpath).

Also, in my zsh I don't declare autoload -U compinit anywhere, this is manged my zsh4humans as far as I know.

I guess this is mainly a problem with my zsh config (zsh4humans).

So I will reach with them ans see if I can fix this. Thanks.


My ~/.zshrc:

autoload -U compinit
compinit -i

autoload colors
colors

I tried this with no avail.

@Farid-NL
Copy link
Contributor Author

Farid-NL commented May 1, 2024

Correction, zsh4humans does have the autoload line, in particular this one: autoload -Uz +X compinit || return.


With the help of this, and editing the completion file rbenv.zsh accordingly:

@@ -2,11 +2,11 @@ if [[ ! -o interactive ]]; then
     return
 fi
 
-compctl -K _rbenv rbenv
+compdef _rbenv rbenv
 
 _rbenv() {
-  local words completions
-  read -cA words
+  local completions
 
   emulate -L zsh
 
@@ -16,5 +16,5 @@ _rbenv() {
     completions="$(rbenv completions ${words[2,-2]})"
   fi
 
-  reply=("${(ps:\n:)completions}")
+  compadd - "${(ps:\n:)completions}"
 }

I got it working

image


I don't know if this will broke someone else completions, but maybe you can test it and if everything works it could be a potential fix for other people with this problem.

@mislav
Copy link
Member

mislav commented May 1, 2024

It's true that we still use the outdated compctl system and that we could potentially migrate to the new completion system, especially to make use of features like autoloading and descriptions.

However, the point that I was making is that even with the compctl-based approach, rbenv zsh completions should work, as evident by them working for me in zsh 5.9 with a very minimal zsh setup. In fact, I've just verified it again: I've started an instance of zsh with no startup files (no zprofile or zshrc), loaded our (legacy) completion script, and it just works. I do not know why it doesn't work for you.

@mislav
Copy link
Member

mislav commented May 1, 2024

Could you run zmodload to check if zsh/compctl is listed?

@Farid-NL
Copy link
Contributor Author

Farid-NL commented May 1, 2024

I've just verified it again: I've started an instance of zsh with no startup files (no zprofile or zshrc), loaded our (legacy) completion script, and it just works. I do not know why it doesn't work for you.

You're right, I tried this as well and it didn't work for me for some reason


Could you run zmodload to check if zsh/compctl is listed?

It is listed, it's the first one to appear.

@mislav
Copy link
Member

mislav commented May 1, 2024

Well, that is really weird.

You're welcome to submit a PR with your changes that transition to compsys! I was hoping to explore improving zsh completions anyway by adding descriptions to completed commands.

@Farid-NL
Copy link
Contributor Author

Farid-NL commented May 1, 2024

Thanks for taking your time to reply btw!

I will submit a PR with those little changes mentioned above that transition to compsys. However it doesn't have descriptions.

I'm actually working in that version (with descriptions), when I finish it (or at least most of it) I will submit another PR.

@mislav
Copy link
Member

mislav commented May 2, 2024

Thanks a lot!

I also had a code spike locally for adding descriptions, so I have added it to your PR. Please take a look before you spend time implementing the same! Of course, simpler approaches than mine are aways welcome.

@Farid-NL
Copy link
Contributor Author

Farid-NL commented May 3, 2024

Fixed in #1569

@Farid-NL Farid-NL closed this as completed May 3, 2024
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