Skip to content

Commit 324dd44

Browse files
authored
Merge pull request #11417 from Freed-Wu/fix-zsh
2 parents e53cf3d + fb45457 commit 324dd44

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

news/11416.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix ``pip completion --zsh``.

src/pip/_internal/commands/completion.py

+4-9
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,10 @@
2222
complete -o default -F _pip_completion {prog}
2323
""",
2424
"zsh": """
25-
function _pip_completion {{
26-
local words cword
27-
read -Ac words
28-
read -cn cword
29-
reply=( $( COMP_WORDS="$words[*]" \\
30-
COMP_CWORD=$(( cword-1 )) \\
31-
PIP_AUTO_COMPLETE=1 $words[1] 2>/dev/null ))
32-
}}
33-
compctl -K _pip_completion {prog}
25+
#compdef -P pip[0-9.]#
26+
compadd $( COMP_WORDS="$words[*]" \\
27+
COMP_CWORD=$((CURRENT-1)) \\
28+
PIP_AUTO_COMPLETE=1 $words[1] 2>/dev/null )
3429
""",
3530
"fish": """
3631
function __fish_complete_pip

tests/functional/test_completion.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,10 @@
4444
(
4545
"zsh",
4646
"""\
47-
function _pip_completion {
48-
local words cword
49-
read -Ac words
50-
read -cn cword
51-
reply=( $( COMP_WORDS="$words[*]" \\
52-
COMP_CWORD=$(( cword-1 )) \\
53-
PIP_AUTO_COMPLETE=1 $words[1] 2>/dev/null ))
54-
}
55-
compctl -K _pip_completion pip""",
47+
#compdef -P pip[0-9.]#
48+
compadd $( COMP_WORDS="$words[*]" \\
49+
COMP_CWORD=$((CURRENT-1)) \\
50+
PIP_AUTO_COMPLETE=1 $words[1] 2>/dev/null )""",
5651
),
5752
(
5853
"powershell",
@@ -392,7 +387,8 @@ def test_completion_path_after_option(
392387
)
393388

394389

395-
@pytest.mark.parametrize("flag", ["--bash", "--zsh", "--fish", "--powershell"])
390+
# zsh completion script doesn't contain pip3
391+
@pytest.mark.parametrize("flag", ["--bash", "--fish", "--powershell"])
396392
def test_completion_uses_same_executable_name(
397393
autocomplete_script: PipTestEnvironment, flag: str, deprecated_python: bool
398394
) -> None:

0 commit comments

Comments
 (0)