dan1994 / pyzshcomplete

Autocompletion for python scripts in zsh
MIT License
23 stars 4 forks source link

Support python modules #30

Open dan1994 opened 4 years ago

dan1994 commented 4 years ago

TL;DR: We currently don't supporting completing modules invoked with python -m <module>, and we should.

It has been quite difficult to support python scripts and modules at the same time.

The easiest way to support python scripts was to use #compdef -P *.py . This is due to the fact that it allows us to be agnostic to the way the the script is invoked:

  1. If the command line is ./script.py, our script will be executed with words=./script.py.
  2. If the command line is python <flags> script.py, then the completion framework will go through python's completion script that will trim everything up to the script itself from words, and then our script will be execited with words=script.py.

In short, this makes identifying the actual script easy, and searching for the magic string easy.

In order to add modules to the mix, we need a different compdef line that will allow us to identify the relevant patterns without messing up what we have already established. This is probably possible, but was difficult enough to postpone it to another time.

It might be useful to try and implement this feature as a separate zsh completion script.