pip icon indicating copy to clipboard operation
pip copied to clipboard

Would you be interested in a better completion for zsh?

Open doronbehar opened this issue 7 years ago • 6 comments

I've wrote a pretty good completion function of pip for ZSH that I'd would like to contribute.

According to ZSH's completions contribution rules, Completions are not accepted when already available in their original project. Since my completion function uses sub functions for completing sub commands and special options arguments etc, it is rather too complex to be inserted inside src/pip/_internal/commands/completion.py.

I think it would be better to put my completion function in a dedicated file and guide users to put in their $fpath. Here is a link to a gist with the whole completion.

doronbehar avatar May 03 '18 13:05 doronbehar

pip's completion is handled in https://github.com/pypa/pip/blob/80b95249ebb7cfe9a69f158db090dc62471bac2b/src/pip/_internal/init.py#L60

pradyunsg avatar May 06 '18 08:05 pradyunsg

Pinging @doronbehar.

pradyunsg avatar May 10 '18 12:05 pradyunsg

Hmm, I've just installed the latest development version of pip from the git repository. I've called the new executable pipdev. With it, pipdev completion --zsh gives me this:

# pip zsh completion start
function _pip_completion {
  local words cword
  read -Ac words
  read -cn cword
  reply=( $( COMP_WORDS="$words[*]" \
             COMP_CWORD=$(( cword-1 )) \
             PIP_AUTO_COMPLETE=1 $words[1] ) )
}
compctl -K _pip_completion pipdev
# pip zsh completion end

Running eval $(pipdev completion --zsh) and afterwards typing pipdev <TAB> doesn't suggest me anything other then fllenames.

Here is the output of pipdev --version:

pip 18.0.dev0 from /home/doron/.virtualenv/pip/lib/python3.6/site-packages/pip-18.0.dev0-py3.6.egg/pip (python 3.6)

doronbehar avatar May 10 '18 14:05 doronbehar

@doronbehar Yeah, it doesn't complete commands. :(

It does complete options though:

$ pip install -<tab>
--build-dir=                 --find-links=                --no-build-isolation         --prefix=                    --src=                       -c
--build-directory=           --force-reinstall            --no-cache-dir               --process-dependency-links   --target=                    -e
--build=                     --global-option=             --no-clean                   --progress-bar=              --timeout=                   -f
--cache-dir=                 --help                       --no-color                   --proxy=                     --trusted-host=              -h
--cert=                      --ignore-installed           --no-compile                 --pypi-url=                  --upgrade                    -i
--client-cert=               --ignore-requires-python     --no-dependencies            --quiet                      --upgrade-strategy=          -q
--compile                    --index-url=                 --no-deps                    --require-hashes             --user                       -r
--constraint=                --install-option=            --no-index                   --requirement=               --verbose                    -t
--default-timeout=           --isolated                   --no-warn-conflicts          --retries=                   --version                    -v
--disable-pip-version-check  --local-log=                 --no-warn-script-location    --root=                      -I
--editable=                  --log-file=                  --only-binary=               --source-dir=                -U
--exists-action=             --log=                       --pre                        --source-directory=          -V
--extra-index-url=           --no-binary=                 --prefer-binary              --source=                    -b

Would you be willing to help out with improving pip's autocompletion, though it'd take the form of writing Python code (specifically https://github.com/pypa/pip/issues/5364#issuecomment-386862143) so that is better? One advantage of doing it in Python is that it's cross shell/platform.

pradyunsg avatar Jun 27 '18 15:06 pradyunsg

That's pretty complicated, I don't know python good enough in order to write something like that by myself. Perhaps I would have attempted doing so if the command line arguments parser was written using a click and I would have just needed to use the completion library of click.

doronbehar avatar Jul 01 '18 09:07 doronbehar

Yeah. We're planning on switching the CLI to click or argparse in the future, instead of pip's homegrown solution.

pradyunsg avatar Jul 01 '18 09:07 pradyunsg

Closing per #11417.

pradyunsg avatar Jul 15 '23 00:07 pradyunsg