1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00

Merge pull request #3859 from c22/master

pip completion for fish shell
This commit is contained in:
Xavier Fernandez 2016-09-23 11:17:55 +02:00 committed by GitHub
commit 72a3d9cbfb
5 changed files with 40 additions and 3 deletions

View file

@ -36,6 +36,8 @@
* Skip scanning virtual environments even when venv/bin/python is a dangling
symlink.
* Added pip completion support for fish shell.
**8.1.2 (2016-05-10)**

View file

@ -424,7 +424,7 @@ Examples:
Command Completion
------------------
pip comes with support for command line completion in bash and zsh.
pip comes with support for command line completion in bash, zsh and fish.
To setup for bash::
@ -434,6 +434,10 @@ To setup for zsh::
$ pip completion --zsh >> ~/.zprofile
To setup for fish::
$ pip completion --fish > ~/.config/fish/completions/pip.fish
Alternatively, you can use the result of the ``completion`` command
directly with the eval function of your shell, e.g. by adding the following to your startup file::

View file

@ -44,7 +44,7 @@ def autocomplete():
"""Command and option completion for the main option parser (and options)
and its subcommands (and options).
Enable by sourcing one of the completion shell scripts (bash or zsh).
Enable by sourcing one of the completion shell scripts (bash, zsh or fish).
"""
# Don't complete if user hasn't sourced bash_completion file.
if 'PIP_AUTO_COMPLETE' not in os.environ:

View file

@ -26,6 +26,14 @@ function _pip_completion {
PIP_AUTO_COMPLETE=1 $words[1] ) )
}
compctl -K _pip_completion pip
""", 'fish': """
function __fish_complete_pip
set -lx COMP_WORDS (commandline -o) ""
set -lx COMP_CWORD (math (contains -i -- (commandline -t) $COMP_WORDS)-1)
set -lx PIP_AUTO_COMPLETE 1
string split \ -- (eval $COMP_WORDS[1])
end
complete -fa "(__fish_complete_pip)" -c pip
"""}
@ -51,6 +59,12 @@ class CompletionCommand(Command):
const='zsh',
dest='shell',
help='Emit completion code for zsh')
cmd_opts.add_option(
'--fish', '-f',
action='store_const',
const='fish',
dest='shell',
help='Emit completion code for fish')
self.parser.insert_option_group(0, cmd_opts)

View file

@ -37,6 +37,23 @@ compctl -K _pip_completion pip"""
assert zsh_completion in result.stdout, 'zsh completion is wrong'
def test_completion_for_fish(script):
"""
Test getting completion for fish shell
"""
fish_completion = """\
function __fish_complete_pip
set -lx COMP_WORDS (commandline -o) ""
set -lx COMP_CWORD (math (contains -i -- (commandline -t) $COMP_WORDS)-1)
set -lx PIP_AUTO_COMPLETE 1
string split \ -- (eval $COMP_WORDS[1])
end
complete -fa "(__fish_complete_pip)" -c pip"""
result = script.pip('completion', '--fish')
assert fish_completion in result.stdout, 'fish completion is wrong'
def test_completion_for_unknown_shell(script):
"""
Test getting completion for an unknown shell
@ -51,7 +68,7 @@ def test_completion_alone(script):
Test getting completion for none shell, just pip completion
"""
result = script.pip('completion', expect_error=True)
assert 'ERROR: You must pass --bash or --zsh' in result.stderr, \
assert 'ERROR: You must pass --bash or --fish or --zsh' in result.stderr, \
'completion alone failed -- ' + result.stderr