I am writing a zsh completion function for a shell script/program I wrote. At some point in the completion process I want to use the completion function of another command to handle the rest of the completion.
How can I find out what the completion function for a specific command is called? How can I look up the existing compdef
assignments in my shell?
My program wraps nvim
and there is no _nvim
function in my shell which I would have guessed would be the completion function. So I assume the completion function that nvim
uses is actually _vim
but this question is more general in order to learn.
Type the command plus a space and then press CtrlX followed by H to the run the _complete_help
widget. For example:
% nvim # press ^Xh here
tags in context :completion::complete:nvim::
argument-rest options (_arguments _vim)
tags in context :completion::complete:nvim:argument-rest:
globbed-files (_files _vim_files _arguments _vim)
This tells you that for arguments to command nvim
, the completion system will call _vim
, which then calls _arguments
, which adds argument-rest
and options
completions. Then, _arguments
calls _vim_files
, which calls _files
, which adds globbed-files
completions.
Alternatively, if you're interested in only the top-level completion function set for a particular command, do this:
% print $_comps[nvim]
_vim