Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Would you be interested in a better completion for zsh? #5364

Closed
doronbehar opened this issue May 3, 2018 · 7 comments
Closed

Would you be interested in a better completion for zsh? #5364

doronbehar opened this issue May 3, 2018 · 7 comments
Labels
C: autocomplete Autocompletion in shells (pip completion)

Comments

@doronbehar
Copy link

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.

@pradyunsg
Copy link
Member

pip's completion is handled in

def autocomplete():

@pradyunsg
Copy link
Member

Pinging @doronbehar.

@pradyunsg pradyunsg added the S: awaiting response Waiting for a response/more information label May 10, 2018
@doronbehar
Copy link
Author

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)

@pradyunsg pradyunsg added the S: needs triage Issues/PRs that need to be triaged label May 11, 2018
@pradyunsg pradyunsg removed S: awaiting response Waiting for a response/more information S: needs triage Issues/PRs that need to be triaged labels Jun 7, 2018
@pradyunsg
Copy link
Member

@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 #5364 (comment)) so that is better? One advantage of doing it in Python is that it's cross shell/platform.

@pradyunsg pradyunsg added S: awaiting response Waiting for a response/more information C: autocomplete Autocompletion in shells (pip completion) labels Jun 27, 2018
@doronbehar
Copy link
Author

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.

@pradyunsg
Copy link
Member

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

@pradyunsg
Copy link
Member

Closing per #11417.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C: autocomplete Autocompletion in shells (pip completion)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants