Search code examples
zsh-completion

How do I find out which function is used for zsh tab completion


I want to know which function zsh is using for tab completion of a command. For many commands (make, ls, cd …) I can apparently guess _<COMMANDNAME>, but I might actually have overriden this setting with compdef _mycd cd.

The reasons why I want to know this are two:

  1. I might want to read some function definitions to use parts of them in functions I'm writing
  2. I want to wrote a completion function which itself calls the completion for other commands (like one does in _nice, with the exception that I might not rely on shift; CURRENT--; _normal)

Solution

  • The current completion rules are stored in $_comps. So one can display the completion rule for cd with echo $_comps[cd] and display the actual function definition with functions $_comps[cd].