I'd like to write a zsh completion for pytest.
Where do I Start? I'm using oh-my-zsh.
in .zshrc:
fpath=($HOME/.mycompletions $fpath)
autoload -U compinit && compinit -u
in $HOME/.mycompletions/_pytest:
#compdef pytest
_pytest()
{
cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=(`pytestcomplete ${cur} 2>/dev/null`)
}
complete -o nospace -F _pytest py.test
Is this correct so far?
Now I "only" need to write the pytestcomplete
script.
What should the Return values Look like? How can I hand over to the script which parts have been completed?
I.e. if a user does py.test<TAB>
it should complete files first.
If one does py.test tests/my.test.py<TAB>
it should complete class names.
If one does py.test tests/my.test.py::TestClass<TAB>
it should complete method names.
To get the info out of pytest, one would use --collect-only
. The only problem at the moment is the back and forth between zsh and the completion script.
And can this be done like this or do I need to write a oh-my-zsh plugin?
COMPREPLY
looks more like bashcompletion than zsh completion, although zsh can use bash completions. Did you check the howtos for zsh and bash?